Message402980
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. |
|
Date |
User |
Action |
Args |
2021-09-30 19:55:16 | aaronwsmith | set | recipients:
+ 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:16 | aaronwsmith | set | messageid: <1633031716.36.0.590938398451.issue17792@roundup.psfhosted.org> |
2021-09-30 19:55:16 | aaronwsmith | link | issue17792 messages |
2021-09-30 19:55:16 | aaronwsmith | create | |
|