From: Jeff Epler Date: Tue, 6 Sep 2022 15:45:23 +0000 (-0500) Subject: Add typing information to micropython X-Git-Url: https://git.ayoreis.com/Adafruit_Blinka-hackapet.git/commitdiff_plain/c468ab77793c856024a966cf5230d4da019bd7a6 Add typing information to micropython This requires converting it into a package so that it can have a "py.typed" file. After this, a package using micropython.const can be type checked --- diff --git a/setup.py b/setup.py index 67ef7ee..4673591 100755 --- a/setup.py +++ b/setup.py @@ -74,7 +74,8 @@ setup( "adafruit_blinka.microcontroller.bcm283x.pulseio": [ "libgpiod_pulsein", "libgpiod_pulsein64", - ] + ], + "micropython": ["py.typed"], }, install_requires=[ "Adafruit-PlatformDetect>=3.13.0", diff --git a/src/micropython.py b/src/micropython/__init__.py similarity index 73% rename from src/micropython.py rename to src/micropython/__init__.py index 4f88543..5f6d73f 100755 --- a/src/micropython.py +++ b/src/micropython/__init__.py @@ -8,22 +8,26 @@ * Author(s): cefn """ +from typing import Callable, TypeVar, Any -def const(x): +Fun = TypeVar("Fun", bound=Callable[..., Any]) + + +def const(x: int) -> int: "Emulate making a constant" return x -def native(f): +def native(f: Fun) -> Fun: "Emulate making a native" return f -def viper(f): +def viper(f: Fun) -> None: "User is attempting to use a viper code emitter" raise SyntaxError("invalid micropython decorator") -def asm_thumb(f): +def asm_thumb(f: Fun) -> None: "User is attempting to use an inline assembler" raise SyntaxError("invalid micropython decorator") diff --git a/src/micropython/py.typed b/src/micropython/py.typed new file mode 100644 index 0000000..e69de29