This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author aaronwsmith
Recipients Arfrever, aaronwsmith, barry, benjamin.peterson, christian.heimes, eric.snow, ezio.melotti, iritkatriel, levkivskyi, ncoghlan, pconnell, pmpp, r.david.murray, serhiy.storchaka
Date 2021-09-30.19:55:16
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1633031716.36.0.590938398451.issue17792@roundup.psfhosted.org>
In-reply-to
Content
I encountered the similar behavior unexpectedly when dealing with LEGB scope of names. Take the following example run under Python 3.9.2:

def doSomething():
    x = 10
    del x
    print(x)

x = 5
doSomething()

This produces a UnboundLocalError at print(x) even though "x" can still be found in the global scope. Indeed if your add print(globals()) before the print(x) line, you can see "x" listed.

By contrast, LEGB scope behavior works as expected in this example:

def doSomething():
    print(x)

x = 5
doSomething()

The former example yielding the UnboundLocalError when dealing with name scope feels like a bug that lines up with the original behavior described in this enhancement request, as I believe "x" is still a bounded name in the global scope, but was explicitly deleted from the local scope.
History
Date User Action Args
2021-09-30 19:55:16aaronwsmithsetrecipients: + aaronwsmith, barry, ncoghlan, christian.heimes, benjamin.peterson, ezio.melotti, Arfrever, r.david.murray, pmpp, eric.snow, serhiy.storchaka, pconnell, levkivskyi, iritkatriel
2021-09-30 19:55:16aaronwsmithsetmessageid: <1633031716.36.0.590938398451.issue17792@roundup.psfhosted.org>
2021-09-30 19:55:16aaronwsmithlinkissue17792 messages
2021-09-30 19:55:16aaronwsmithcreate