Skip to content
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

Assignment expression raises error if updating global variable #14376

Open
2 tasks done
rkompass opened this issue Apr 25, 2024 · 1 comment
Open
2 tasks done

Assignment expression raises error if updating global variable #14376

rkompass opened this issue Apr 25, 2024 · 1 comment
Labels

Comments

@rkompass
Copy link

rkompass commented Apr 25, 2024

Checks

  • I agree to follow the MicroPython Code of Conduct to ensure a safe and respectful space for everyone.

  • I've searched for existing issues matching this bug, and didn't find any.

Port, board and/or hardware

w600, RP2, others

MicroPython version

MicroPython v1.23.0-preview.362.g3995158d9.dirty on 2024-04-19

Reproduction

a=0; print([(a:=a+1) for b in range(10)])

Expected behaviour

[1, 2, 3, 4, 5, 6, 7, 8, 9, 10]

Observed behaviour

SyntaxError: identifier redefined as global

Additional Information

I saw the discussion on #4908
but there it is about a variable created in the comprehension context being available as global outside.

Here is a variable already present as global.

@rkompass rkompass added the bug label Apr 25, 2024
@Gadgetoid
Copy link
Contributor

Similarly weird case:

CPython 3.12.2:

>>> global a; a=0; print([(a:=a+1) for b in range(10)])
[1, 2, 3, 4, 5, 6, 7, 8, 9, 10]

MicroPython (UNIX standard):

>>> global a; a=0; print([(a:=a+1) for b in range(10)])
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "<stdin>", line 1, in <listcomp>
NameError: local variable referenced before assignment

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

2 participants