python-stdlib: Add typing modules that can be frozen or mip installable. #1051
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This is a improved MicroPython alternative to
based on all the above and tuned for reduced firmware/frozen size, while keeping provable consistence with the relevant typing PEPs for features that are supported by MicroPython.
It consists of a number of modules that can be mip-installed or frozen as part of a firmware..
Note that the modules have been optimized for size - somewhat impacting readability - but where relevant the orignal code has been kept as comments.
Documentation
Documentation is not created yet.
Testing:
The same set of tests has been run against both implementations and while there are a few differences , both pass the majority of tests.
The remaining differences to CPython should be documented as such, and then can be excluded from the verification tests.
The tests are created at part of MicroPython's tests suite , and are mot included in this PR.
Currently they are part of micropython/micropython#15911, but could be separated for testing ( may require a new variant for testing in this in the MicroPython repo)
The PR includes the
bundle-typing
to allow simple addition to a board defintitionThis also defaults the mpy-cross opt level to 3, to reduce firmware size.
The impact to firmware size of the
modtyping.c
and thetyping.py
variant are surprisingly close,although I think there may be room for additional optimisation for the
modtyping.c
alternative.Comparison without collections.abc
Note: both PRs are changing , so the below is a point-in-time comparison ( 14/10/'25)
Test Results:
Comparison including collections.abc
Test results: