Repository navigation
Turbo : Let fast native code fall back to plain Python when a board can't run it - #11529
Merged
Merged
Conversation
Where native code can't be emitted (on the board, or mpy-cross with no -march), a function marked optional=True compiles as bytecode. Without it the board now says "native code not supported on this board" instead of "invalid micropython decorator". Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
dhalbert
requested changes
Oct 8, 2026
dhalbert
left a comment
Collaborator
There was a problem hiding this comment.
small query about possible code size shrink
Reuse the existing "invalid micropython decorator" error and drop the argument check, so pewpew_lcd fits again. optional=True still compiles as bytecode where native code can't be emitted; other arguments are ignored, as before. Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
dhalbert
approved these changes
Oct 9, 2026
dhalbert
left a comment
Collaborator
There was a problem hiding this comment.
I am just curious why you removed the syntax test.
I tried changing the True test to use mp_parse_const_true(). It is 28 bytes longer. The advantage is that it matches "triush" args like 1. But that's not a big deal.
Collaborator
Author
|
@dhalbert I took out the extra check to save space, so something like That left the error test with nothing to test, so I removed it. The test for And I agree, 28 bytes isn't worth it just to accept |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
What
@micropython.native(optional=True)@micropython.viper(optional=True)both run as plain Python where native code can't be made
Why
Library authors can ship one
.pywith turbo code that builds in the bundles and runs on every board.mpy-cross foo.py(no-march, what bundle CI runs)SyntaxError: invalid archfoo.mpympy-cross -march=<arch> foo.py.pyon a boardSyntaxError: invalid micropython decoratoroptional=True,.pyon a boardinvalid micropython decoratornative code not supported on this boardoptional=anything butTrue/False, or other argumentsinvalid micropython decoratorAgreed with @dhalbert on Discord after @todbot asked how a bundle library can use viper.
CircuitPython only; micropython#15615 is the upstream request.
Cost: Metro M0 Express +140 bytes (
el, 668 free).Tests
New
tests/micropython/decorator_optional.pyanddecorator_optional_error.py. CI's unix build has an emitter, so the board fallback is hardware-tested only..pyruns@viperAI assistance
Claude was used.