Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Open
Josverl wants to merge3 commits intomicropython:master
base:master
Choose a base branch
Loading
fromJosverl:add_typing_py

Conversation

@Josverl
Copy link

@JosverlJosverl commentedOct 14, 2025
edited
Loading

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.

  • Document availability of the modules
  • Document the use of the bundle-typing and it's options

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 ofmicropython/micropython#15911, but could be separated for testing ( may require a new variant for testing in this in the MicroPython repo)

The PR includes thebundle-typing to allow simple addition to a board defintition

# typing related modulesrequire("bundle-typing",# extensions=False,  # Set to True to include collections.abc# opt_level=2,)

This also defaults the mpy-cross opt level to 3, to reduce firmware size.

The impact to firmware size of themodtyping.c and thetyping.py variant are surprisingly close,
although I think there may be room for additional optimisation for themodtyping.c alternative.

Comparison without collections.abc

Note: both PRs are changing , so the below is a point-in-time comparison ( 14/10/'25)

methodmodules includedsize (bytes)diff
standard-841_2950
modtyping.cno collections.abc8438872592
typing.pyno collections.abc8438072.512 (-80)

Test Results:

ModulecountFIXME
typing.py3
- [ ] FIXME: from collections.abc import Callable
- [ ] FIXME: document cpy_diff - get_args(int) should be ()
- [ ] FIXME: document cpydiff : Final cannot be used with container types
modtyping.c6
- [ ] FIXME: Difference or Crash - multiple bases have instance lay-out conflict: multiple bases have instance lay-out conflict
- [ ] FIXME: Difference or Crash - multiple bases have instance lay-out conflict: multiple bases have instance lay-out conflict
- [ ] FIXME: from collections.abc import Callable
- [ ] FIXME: document cpy_diff - get_origin(str) should be None
- [ ] FIXME: document cpy_diff - get_args(int) should be ()
- [ ] FIXME: document cpydiff : Final cannot be used with container types

Comparison including collections.abc

methodmodules includedsize (bytes)diff
standard-841_2950
modtyping.cno collections.abc843_8872592
typing.pywith collections.abc844_0632668 (+76 bytes)

Test results:

ModulecountFIXME
typing.py2Size: 844063
- [ ] FIXME: document cpy_diff - get_args(int) should be ()
- [ ] FIXME: document cpydiff : Final cannot be used with container types
modtyping.c6Size: 843887
- [ ] FIXME: Difference or Crash - multiple bases have instance lay-out conflict: multiple bases have instance lay-out conflict
- [ ] FIXME: Difference or Crash - multiple bases have instance lay-out conflict: multiple bases have instance lay-out conflict
- [ ] FIXME: from collections.abc import Callable
- [ ] FIXME: document cpy_diff - get_origin(str) should be None
- [ ] FIXME: document cpy_diff - get_args(int) should be ()
- [ ] FIXME: document cpydiff : Final cannot be used with container types

typing, typing_extensions and collections.abcSigned-off-by: Jos Verlinde <jos_verlinde@hotmail.com>
`__future__`, `abc`, `collection`Signed-off-by: Jos Verlinde <jos_verlinde@hotmail.com>
This also defaults the mpy-cross opt level to 3, to reduce firmware size.Signed-off-by: Jos Verlinde <jos_verlinde@hotmail.com>
@Josverl
Copy link
Author

@stinos, could you please review ?

@stinos
Copy link

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 None isTrue but 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.

@Josverl
Copy link
Author

Josverl commentedOct 14, 2025
edited
Loading

@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
Copy link

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

Josverl reacted with thumbs up emoji

@JosverlJosverl added the enhancementFeature requests, new feature implementations labelOct 16, 2025
Sign up for freeto join this conversation on GitHub. Already have an account?Sign in to comment

Reviewers

@dpgeorgedpgeorgeAwaiting requested review from dpgeorge

Assignees

No one assigned

Labels

enhancementFeature requests, new feature implementations

Projects

None yet

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

2 participants

@Josverl@stinos

[8]ページ先頭

©2009-2025 Movatter.jp