diff --git a/mip/abc.mpy b/mip/abc.mpy new file mode 100644 index 000000000..9cd42827e Binary files /dev/null and b/mip/abc.mpy differ diff --git a/mip/abc.py b/mip/abc.py new file mode 100644 index 000000000..fb99edbab --- /dev/null +++ b/mip/abc.py @@ -0,0 +1,13 @@ +""" +abc.py - Micropython runtime Abstract Base Classes module +""" + +from typing import _any_call # type: ignore + + +def abstractmethod(funcobj): + return funcobj + + +def __getattr__(attr): + return _any_call diff --git a/mip/typing.mpy b/mip/typing.mpy index 42f6ad904..aa492df55 100644 Binary files a/mip/typing.mpy and b/mip/typing.mpy differ diff --git a/mip/typing.py b/mip/typing.py index 3be3ceb30..fc3f7323f 100644 --- a/mip/typing.py +++ b/mip/typing.py @@ -1,3 +1,9 @@ +""" +This module provides runtime support for type hints. +based on : https://github.com/micropython/micropython-lib/pull/584 +""" + + def cast(type, val): return val @@ -18,7 +24,13 @@ def overload(func): return None +def NewType(name, type): + return type + + class _AnyCall: + """A class to ignore type hints in code.""" + def __init__(*args, **kwargs): pass @@ -26,131 +38,14 @@ def __call__(*args, **kwargs): pass def __getitem__(self, arg): - return _anyCall - -_anyCall = _AnyCall() - - -class _SubscriptableType: - def __getitem__(self, arg): - return _anyCall - - -_Subscriptable = _SubscriptableType() - - -def TypeVar(type, *types): - return None - - -def NewType(name, type): - return type - - -class Any: - pass - - -class BinaryIO: - pass - - -class ClassVar: - pass - + return _any_call -class Final: - pass +_any_call = _AnyCall() -class Hashable: - pass - - -class IO: - pass - - -class NoReturn: - pass - - -class Sized: - pass - - -class SupportsInt: - pass - - -class SupportsFloat: - pass - - -class SupportsComplex: - pass - - -class SupportsBytes: - pass - - -class SupportsIndex: - pass - - -class SupportsAbs: - pass - - -class SupportsRound: - pass - - -class TextIO: - pass - - -AnyStr = str -Text = str -Pattern = str -Match = str -TypedDict = dict +TYPE_CHECKING = False -AbstractSet = _Subscriptable -AsyncContextManager = _Subscriptable -AsyncGenerator = _Subscriptable -AsyncIterable = _Subscriptable -AsyncIterator = _Subscriptable -Awaitable = _Subscriptable -Callable = _Subscriptable -ChainMap = _Subscriptable -Collection = _Subscriptable -Container = _Subscriptable -ContextManager = _Subscriptable -Coroutine = _Subscriptable -Counter = _Subscriptable -DefaultDict = _Subscriptable -Deque = _Subscriptable -Dict = _Subscriptable -FrozenSet = _Subscriptable -Generator = _Subscriptable -Generic = _Subscriptable -Iterable = _Subscriptable -Iterator = _Subscriptable -List = _Subscriptable -Literal = _Subscriptable -Mapping = _Subscriptable -MutableMapping = _Subscriptable -MutableSequence = _Subscriptable -MutableSet = _Subscriptable -NamedTuple = _Subscriptable -Optional = _Subscriptable -OrderedDict = _Subscriptable -Sequence = _Subscriptable -Set = _Subscriptable -Tuple = _Subscriptable -Type = _Subscriptable -Union = _Subscriptable -TYPE_CHECKING = False +# ref: https://github.com/micropython/micropython-lib/pull/584#issuecomment-2317690854 +def __getattr__(attr): + return _any_call diff --git a/mip/typing_extensions.mpy b/mip/typing_extensions.mpy index f486720a1..fb85fede0 100644 Binary files a/mip/typing_extensions.mpy and b/mip/typing_extensions.mpy differ diff --git a/mip/typing_extensions.py b/mip/typing_extensions.py index 30c0706fd..fc3f7323f 100644 --- a/mip/typing_extensions.py +++ b/mip/typing_extensions.py @@ -1,3 +1,9 @@ +""" +This module provides runtime support for type hints. +based on : https://github.com/micropython/micropython-lib/pull/584 +""" + + def cast(type, val): return val @@ -18,137 +24,28 @@ def overload(func): return None +def NewType(name, type): + return type + + class _AnyCall: + """A class to ignore type hints in code.""" + def __init__(*args, **kwargs): pass def __call__(*args, **kwargs): pass - -_anyCall = _AnyCall() - - -class _SubscriptableType: def __getitem__(self, arg): - return _anyCall - - -_Subscriptable = _SubscriptableType() - - -def TypeVar(type, *types): - return None - - -def NewType(name, type): - return type - - -class Any: - pass - - -class BinaryIO: - pass - - -class ClassVar: - pass - + return _any_call -class Final: - pass +_any_call = _AnyCall() -class Hashable: - pass - - -class IO: - pass - - -class NoReturn: - pass - - -class Sized: - pass - - -class SupportsInt: - pass - - -class SupportsFloat: - pass - - -class SupportsComplex: - pass - - -class SupportsBytes: - pass - - -class SupportsIndex: - pass - - -class SupportsAbs: - pass - - -class SupportsRound: - pass - - -class TextIO: - pass - - -AnyStr = str -Text = str -Pattern = str -Match = str -TypedDict = dict +TYPE_CHECKING = False -AbstractSet = _Subscriptable -AsyncContextManager = _Subscriptable -AsyncGenerator = _Subscriptable -AsyncIterable = _Subscriptable -AsyncIterator = _Subscriptable -Awaitable = _Subscriptable -Callable = _Subscriptable -ChainMap = _Subscriptable -Collection = _Subscriptable -Container = _Subscriptable -ContextManager = _Subscriptable -Coroutine = _Subscriptable -Counter = _Subscriptable -DefaultDict = _Subscriptable -Deque = _Subscriptable -Dict = _Subscriptable -FrozenSet = _Subscriptable -Generator = _Subscriptable -Generic = _Subscriptable -Iterable = _Subscriptable -Iterator = _Subscriptable -List = _Subscriptable -Literal = _Subscriptable -Mapping = _Subscriptable -MutableMapping = _Subscriptable -MutableSequence = _Subscriptable -MutableSet = _Subscriptable -NamedTuple = _Subscriptable -Optional = _Subscriptable -OrderedDict = _Subscriptable -Sequence = _Subscriptable -Set = _Subscriptable -Tuple = _Subscriptable -Type = _Subscriptable -Union = _Subscriptable -TYPE_CHECKING = False +# ref: https://github.com/micropython/micropython-lib/pull/584#issuecomment-2317690854 +def __getattr__(attr): + return _any_call