Skip to content

mpy-cross compiles bad code #17255

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

Closed
Tangerino opened this issue May 6, 2025 · 2 comments
Closed

mpy-cross compiles bad code #17255

Tangerino opened this issue May 6, 2025 · 2 comments
Labels

Comments

@Tangerino
Copy link

Port, board and/or hardware

ESP32

MicroPython version

MicroPython v1.23.0-preview.332.g49ce7a607.dirty on 2024-04-22; mpy-cross emitting mpy v6.3

Reproduction

This code

from typing import List

my_list: List = []

print(mylist)

Fails to run, as expected

>>> import typing
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
ImportError: no module named 'typing'
>>> import typing_test
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "typing_test.py", line 1, in <module>
ImportError: no module named 'typing'

But can be compiled as in:

Image

Expected behaviour

Expected compilation error since the module does not exists

Observed behaviour

I expected an output error since the module typing does not exists and I discovered this only in runtime

Additional Information

No, I've provided everything above.

Code of Conduct

Yes, I agree

@Tangerino Tangerino added the bug label May 6, 2025
@Josverl
Copy link
Contributor

Josverl commented May 6, 2025

I do not consider this a bug,
Whether or not a typing module is available at runtime, does not, and should not matter to producing byte-code.

There is another issue in your example my_list: List = [] is an Annotated Assign (annassign), where the type annotation : List is ignored by the MicroPython lexer/parser , essentially downgrading it to just an Assign.

if (kind == PN_annassign) {

The documentation is somewhat confusing on this this, as PEP 562 is documented as completed.

One could say that the documentation should read : Partially implemented. The syntax is accepted , but the annotations are not parsed / compiled.

also see the PR that introduced this: #6126

@peterhinch
Copy link
Contributor

Closing. This is not a bug for the reason stated

Whether or not a typing module is available at runtime, does not, and should not matter to producing byte-code.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants