← index #14376Issue #14397
Off-topic · high · value 3.155
QUERY · ISSUE

Assignment expression raises error if updating global variable

openby rkompassopened 2024-04-25updated 2024-04-25
bug

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.

CANDIDATE · ISSUE

Viper: Unary minus changes rhs variable in place, even if assigned to new lhs variable.

openby rkompassopened 2024-04-30updated 2024-04-30
bug

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.

Keyboard

j / / n
next pair
k / / p
previous pair
1 / / h
show query pane
2 / / l
show candidate pane
c
copy suggested comment
r
toggle reasoning
g i
go to index
?
show this help
esc
close overlays

press ? or esc to close

copied