Assignment expression raises error if updating global variable
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 https://github.com/micropython/micropython/pull/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.
Viper: Unary minus changes rhs variable in place, even if assigned to new lhs variable.
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
latest, e.g.: MicroPython v1.23.0-preview.344.gb1ac266bb on 2024-04-29; Raspberry Pi Pico W with RP2040
Reproduction
@micropython.viper
def vip_unaryminus() -> int:
a = 5
b = -a
return a+b
print(vip_unaryminus()) # -10 <---- error, should be 0
@micropython.viper
def vip_tuple_um():
a:int = int(-5)
b = -a
return (a, b)
print(vip_tuple_um()) # (5, 5) <---- error, should be (-5, 5)
Expected behaviour
0 # as 5 and -5 cancel out, so 5 + (-5) = 0
(-5, 5)
Observed behaviour
-10
(5, 5)
Additional Information
No, I've provided everything above.
My interpretation of this errorneaous behaviour is in the issue heading.
Thank you, btw., for improving viper permanently.