New submission from whitequark: 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'>) ---------- components: Interpreter Core messages: 244356 nosy: whitequark priority: normal severity: normal status: open title: interaction of nonlocal and except leading to incorrect behavior type: behavior versions: Python 3.4 _______________________________________ Python tracker <rep...@bugs.python.org> <http://bugs.python.org/issue24321> _______________________________________ _______________________________________________ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com