Author whitequark
Recipients whitequark
Date 2015-05-29.01:55:24
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1432864526.16.0.510004554687.issue24321@psf.upfronthosting.co.za>
In-reply-to
Content
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'>)
History
Date User Action Args
2015-05-29 01:55:26whitequarksetrecipients: + whitequark
2015-05-29 01:55:26whitequarksetmessageid: <1432864526.16.0.510004554687.issue24321@psf.upfronthosting.co.za>
2015-05-29 01:55:25whitequarklinkissue24321 messages
2015-05-29 01:55:24whitequarkcreate