Skip to content

mpy/sagas: Get imported modules from compiled .mpy. - #2373

Open
dlech wants to merge 1 commit into
masterfrom
mpy-imports
Open

mpy/sagas: Get imported modules from compiled .mpy.#2373
dlech wants to merge 1 commit into
masterfrom
mpy-imports

Conversation

@dlech

@dlech dlech commented Sep 7, 2026

Copy link
Copy Markdown
Member

We were parsing Python in JavaScript to find imports, using a jison parser that allocated memory proportional to lines times file size, so large programs could exhaust browser memory. The grammar also rejected f-strings containing the same quote character and decimal literals with a leading zero, and since parse errors were swallowed, any such program silently downloaded with no modules at all.

Read the imports back out of the .mpy instead. Each module is already compiled by mpy-cross, so this removes a pass rather than adding one, and MicroPython's own compiler decides what an import is.

Fixes: pybricks/support#1804
Fixes: pybricks/support#1954
Fixes: pybricks/support#1981
Assisted-by: Claude Opus 5 noreply@anthropic.com

We were parsing Python in JavaScript to find imports, using a jison
parser that allocated memory proportional to lines times file size, so
large programs could exhaust browser memory. The grammar also rejected
f-strings containing the same quote character and decimal literals with
a leading zero, and since parse errors were swallowed, any such program
silently downloaded with no modules at all.

Read the imports back out of the .mpy instead. Each module is already
compiled by mpy-cross, so this removes a pass rather than adding one,
and MicroPython's own compiler decides what an import is.

Fixes: pybricks/support#1804
Fixes: pybricks/support#1954
Fixes: pybricks/support#1981
Assisted-by: Claude Opus 5 <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

1 participant