[issue24321] interaction of nonlocal and except leading to incorrect behavior

2015-05-29 Thread R. David Murray
R. David Murray added the comment: Indeed, if you replace the except clause with a 'del x', you get the same UnboundLocalError. This is working as designed. -- nosy: +r.david.murray ___ Python tracker ___

[issue24321] interaction of nonlocal and except leading to incorrect behavior

2015-05-28 Thread Ned Deily
Changes by Ned Deily : -- stage: -> resolved status: open -> closed ___ Python tracker ___ ___ Python-bugs-list mailing list Unsubscr

[issue24321] interaction of nonlocal and except leading to incorrect behavior

2015-05-28 Thread Martin Panter
Martin Panter added the comment: The first example seems to behave as I would expect. The UnboundLocalError is raised by the print() call, because the “x” variable has been deleted by the exception handler. Equivalent code without using “nonlocal”: >>> def f(): ... x = None ... try: ..

[issue24321] interaction of nonlocal and except leading to incorrect behavior

2015-05-28 Thread Eric Snow
Changes by Eric Snow : -- nosy: +benjamin.peterson ___ Python tracker ___ ___ Python-bugs-list mailing list Unsubscribe: https://mail

[issue24321] interaction of nonlocal and except leading to incorrect behavior

2015-05-28 Thread Yury Selivanov
Changes by Yury Selivanov : -- nosy: +yselivanov ___ Python tracker ___ ___ Python-bugs-list mailing list Unsubscribe: https://mail.p

[issue24321] interaction of nonlocal and except leading to incorrect behavior

2015-05-28 Thread whitequark
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 pr