-
Couldn't load subscription status.
- Fork 1.1k
python-stdlib: Add typing modules that can be frozen or mip installable. #1051
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
typing, typing_extensions and collections.abc Signed-off-by: Jos Verlinde <jos_verlinde@hotmail.com>
`__future__`, `abc`, `collection` Signed-off-by: Jos Verlinde <jos_verlinde@hotmail.com>
76d9b9c to
2bab830
Compare
This also defaults the mpy-cross opt level to 3, to reduce firmware size. Signed-off-by: Jos Verlinde <jos_verlinde@hotmail.com>
2bab830 to
6868a06
Compare
@stinos, could you please review ?
stinos
commented
Oct 14, 2025
To make comparisons easier, could you share gcc/micropython version and a script which you used, or even just a set of commands, to get these results? Having rebased my code on master and comparing sizes and results, things seem different for me so I want to make sure we're doing roughly the same thing; for instance:
- a unix build with everything from this PR enabled is 3072 bytes larger than the standard build, compared to 2668 from your results. That seems substantial.
- in that same build,
typing.get_origin(str) is NoneisTruebut according to your results it should pass
In any case, I'm hitting something funny; I made a windows msvc build with your typing bundle, I can see frozen_content.c including the frozen typing code code, yet I get an ImportError trying to import any of the modules contained in the manifest. Probably I'm gonna try and sort that out first.
@stinos ,
please find the notebook and the supporting files for the 'jos' variant in the gist.
https://gist.github.com/Josverl/f953fb49a4cac63759bd2056f728a725#file-readme-md
I built locally on WSL Ubuntu 22.04.5 LTS with :
gcc (Ubuntu 11.4.0-1ubuntu1~22.04.2) 11.4.0
stinos
commented
Oct 16, 2025
I get an ImportError trying to import any of the modules contained in the manifest
Oops, my MICROPYPATH didn't have a .frozen entry.
please find the notebook and the supporting files for the 'jos' variant in the gist.
Ok thanks. I was doing almost the same, however using multiple variants in different branches where I might have messed something up at the time I wrote the previous comment, and using gcc 9.4 or so. Will check again next week. Not sure if this is of any use, but here's a PS script for comparing typing variants: https://gist.github.com/stinos/2ee6138679a39a75628f85b5765a71b1
Uh oh!
There was an error while loading. Please reload this page.
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-typingto 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.cand thetyping.pyvariant are surprisingly close,although I think there may be room for additional optimisation for the
modtyping.calternative.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: