Replies: 2 comments 4 replies
-
There's multiple levels you could go here. At one extreme, if you want to support thorough runtime typing libraries (e.g., Pydantic, typeguard, beartype), you need to basically replicate all of At the other extreme, many users who use only static typing don't look at the annotations at runtime at all. However, you still need to support those pieces of typing syntax that are not placed in annotations at runtime, such as TypedDict and NamedTuple class definitions, TypeVar and NewType definitions, cast() calls, generic base classes, various decorators, and a few others. In the middle, there is the light introspection used by some parts of the standard library. For example, |
Beta Was this translation helpful? Give feedback.
-
@JelleZijlstra there's a lot of backstory in the linked discussions, but the basic concept is for development to use cpython and associated type checking tooling in conjunction with micropython stubs (which @Josverl already builds publishes). To be able to use some desktop type checking tooling and support other libraries that also use desktop type checking tooling micropython itself need to support / ignore a certain level of type annotation / typing features in the python code itself. MicroPython doesn't need to run the tooling or understand the typing, the syntax just needs to not get in the way or break micropython. What we need to figure out is just how much of the typing syntax and more "advanced" in-code features are worth supporting (ignoring) |
Beta Was this translation helpful? Give feedback.
-
We are working to add 'just enough' runtime support to MicroPython to support the use of code using inline type annotations.
As MicroPython is intended to run on CPU and memory constrained devices, the goal is to keep the code and runtime overhead as small as possible.
The MicroPython parser already ignores most method and parameter type annotations so the plan is to add very minimal
typing
,__futures__
,typing_extensions
,abc
andcollection.abc
modules, with the primary intent to not fail imports and runtime expressions.that still leaves a number of expressions/methods that are/need to be evaluated at runtime.
We have a few working prototypes 1,2,3 that appear to work, that I want to compare/validate for correct runtime behavior.
I have gathered samples from the typing docs and https://typing.readthedocs.io/ into a notebook running the code snippets on a MCU or unix version of MicroPython for validation and experimentation.
After we have a solid set of test these will be integrated with the CI/CD .
Part of the challenge is finding what runtime behavior should be tested , and what code snippets to use for that, but I'm pretty sure I have not thought of everything needed.
I have looked for (python based) tests to verify correct runtime behavior,
or even for a list of typing-related runtime behaviors that need testing , and not been able to find that thus far.
Any pointers or assistance is welcome.
Beta Was this translation helpful? Give feedback.
All reactions