]> Repositories - Adafruit_Blinka-hackapet.git/commitdiff
Add typing information to micropython typing-micropython
authorJeff Epler <jepler@gmail.com>
Tue, 6 Sep 2022 15:45:23 +0000 (10:45 -0500)
committerJeff Epler <jepler@gmail.com>
Tue, 6 Sep 2022 15:52:30 +0000 (10:52 -0500)
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

setup.py
src/micropython/__init__.py [moved from src/micropython.py with 73% similarity]
src/micropython/py.typed [new file with mode: 0644]

index 67ef7ee4c7d30cf86fa36f2fabb0affb246ae53d..4673591e6faf336b50a7efebc9c09e580c6e0dd2 100755 (executable)
--- 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",
similarity index 73%
rename from src/micropython.py
rename to src/micropython/__init__.py
index 4f88543d5f52bfcc0d5badeee0fbd1c992c06766..5f6d73fe0980f811bbb37e73b63de7c3c0c8839b 100755 (executable)
@@ -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 (file)
index 0000000..e69de29