|
| 1 | +""" |
| 2 | +MicroPython-stubs base types that are not present in typeshed. |
| 3 | +
|
| 4 | +This is a collection of types that are not present in typeshed, but are used in the micropython stubs. |
| 5 | +
|
| 6 | +Common cases are: |
| 7 | +- MicroPython implementation is different from CPython, so the types are different. |
| 8 | +- MicroPython has some types that are not present in CPython. |
| 9 | +
|
| 10 | +""" |
| 11 | + |
| 12 | +from __future__ import annotations |
| 13 | + |
| 14 | +import abc # type: ignore - not collections.abc |
| 15 | +import sys |
| 16 | + |
| 17 | +from typing import Final, final |
| 18 | + |
| 19 | +from _typeshed import Incomplete, structseq, AnyStr_co |
| 20 | +from typing_extensions import TypeAlias, TypeVar |
| 21 | + |
| 22 | +from .subscriptable import Subscriptable as Subscriptable |
| 23 | +from .IRQs import _IRQ |
| 24 | +from .neopixelbase import _NeoPixelBase as _NeoPixelBase |
| 25 | +from .blockdevice import ( |
| 26 | + _BlockDeviceProtocol as _BlockDeviceProtocol, |
| 27 | + _OldAbstractBlockDev, |
| 28 | + _OldAbstractReadOnlyBlockDev, |
| 29 | +) |
| 30 | +from .buffer_mp import AnyReadableBuf as AnyReadableBuf, AnyWritableBuf as AnyWritableBuf |
| 31 | + |
| 32 | +from .io_mp import ( |
| 33 | + BytesIO as BytesIO, |
| 34 | + FileIO as FileIO, |
| 35 | + IncrementalNewlineDecoder as IncrementalNewlineDecoder, |
| 36 | + StringIO as StringIO, |
| 37 | + TextIOWrapper as TextIOWrapper, |
| 38 | + IOBase_mp as IOBase_mp, |
| 39 | + _BufferedIOBase, |
| 40 | + _IOBase, |
| 41 | + _RawIOBase, |
| 42 | + _TextIOBase, |
| 43 | + open as open, |
| 44 | +) |
| 45 | + |
| 46 | +from .time_mp import _TimeTuple as _TimeTuple |
| 47 | +from .pathlike import PathLike as PathLike |
| 48 | + |
| 49 | +from .mp_implementation import _mp_implementation as _mp_implementation |
| 50 | +from .mp_available import mp_available as mp_available |
| 51 | +# ------------------ |
| 52 | +# copied from _typeshed os.pyi as os.pyi cannot import from a module with the same name |
| 53 | +GenericAlias = type(list[int]) |
| 54 | + |
| 55 | +# ------------------------------------------------------------------------------------ |
| 56 | +StrOrBytesPath: TypeAlias = str | bytes | PathLike[str] | PathLike[bytes] |
| 57 | +_StrOrBytesT = TypeVar("_StrOrBytesT", str, bytes) |
| 58 | + |
| 59 | +# ------------------------------------------------------------------------------------ |
| 60 | +_AnyPath: TypeAlias = str | bytes | PathLike[str] | PathLike[bytes] |
| 61 | +_FdOrAnyPath: TypeAlias = int | _AnyPath |
| 62 | + |
| 63 | +# ------------------------------------------------------------------------------------ |
| 64 | +# HID_Tuple is used in multiple pyb.submodules |
| 65 | +HID_Tuple: TypeAlias = tuple[int, int, int, int, bytes] |
| 66 | + |
| 67 | +# ------------------------------------------------------------------------------------ |
| 68 | +# copied from _typeshed os.pyi as os.pyi cannot import from a module with the same nam@final |
| 69 | +@final |
| 70 | +class uname_result(structseq[str], tuple[str, str, str, str, str]): |
| 71 | + if sys.version_info >= (3, 8): |
| 72 | + __match_args__: Final = ("sysname", "nodename", "release", "version", "machine") |
| 73 | + |
| 74 | + @property |
| 75 | + def sysname(self) -> str: ... |
| 76 | + @property |
| 77 | + def nodename(self) -> str: ... |
| 78 | + @property |
| 79 | + def release(self) -> str: ... |
| 80 | + @property |
| 81 | + def version(self) -> str: ... |
| 82 | + @property |
| 83 | + def machine(self) -> str: ... |
| 84 | + |
| 85 | +# ------------------------------------------------------------------------------------ |
| 86 | + |
| 87 | +########################### |
| 88 | +# HashLib |
| 89 | + |
| 90 | +# manual addition to hashlib.pyi |
| 91 | + |
| 92 | +class _Hash(abc.ABC): |
| 93 | + """ |
| 94 | + Abstract base class for hashing algorithms that defines methods available in all algorithms. |
| 95 | + """ |
| 96 | + |
| 97 | + def update(self, data: AnyReadableBuf, /) -> None: |
| 98 | + """ |
| 99 | + Feed more binary data into hash. |
| 100 | + """ |
| 101 | + |
| 102 | + def digest(self) -> bytes: |
| 103 | + """ |
| 104 | + Return hash for all data passed through hash, as a bytes object. After this |
| 105 | + method is called, more data cannot be fed into the hash any longer. |
| 106 | + """ |
| 107 | + |
| 108 | + def hexdigest(self) -> str: |
| 109 | + """ |
| 110 | + This method is NOT implemented. Use ``binascii.hexlify(hash.digest())`` |
| 111 | + to achieve a similar effect. |
| 112 | + """ |
0 commit comments