Message244356
To reproduce in Python 3.4.2:
def f():
x = None
def g():
nonlocal x
try:
raise Exception()
except Exception as x:
pass
g()
# ↓ UnboundLocalError: local variable 'x' referenced before assignment
print("x", x)
f()
Compare this to:
def f():
x = None
def g():
nonlocal x
with open("/dev/null") as x:
pass
g()
print("x", x)
f()
(which prints: x <_io.TextIOWrapper name='/dev/null' mode='r' encoding='UTF-8'>) |
|
Date |
User |
Action |
Args |
2015-05-29 01:55:26 | whitequark | set | recipients:
+ whitequark |
2015-05-29 01:55:26 | whitequark | set | messageid: <1432864526.16.0.510004554687.issue24321@psf.upfronthosting.co.za> |
2015-05-29 01:55:25 | whitequark | link | issue24321 messages |
2015-05-29 01:55:24 | whitequark | create | |
|