Message245558
With the fact that the existence of "Python without closures" predates Python 2.2, this now reads like a straight up compiler bug to me.
Compare the behaviour with no local assignment in the class body:
>>> def f():
... n = 1
... class C:
... print(n)
...
>>> f()
1
To the behaviour once the local is assigned:
>>> def f():
... n = 1
... class C:
... n = n
... print(n)
...
>>> f()
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "<stdin>", line 3, in f
File "<stdin>", line 4, in C
NameError: name 'n' is not defined
The issue is that the latter will still emit a LOAD_NAME/STORE_NAME pair, while the former emits LOAD_CLASSDEREF (and has emitted LOAD_DEREF for as long as I can recall hacking on the compiler).
Off the top of my head, I'm not sure our current symbol table analysis pass can actually cope with this idea though - it would require separating "just a class body local, which may or may not first be retrieved as a global or builtin" from "a class body local which is first retrieved from a closure reference". |
|
Date |
User |
Action |
Args |
2015-06-20 11:01:47 | ncoghlan | set | recipients:
+ ncoghlan, arigo, terry.reedy, ethan.furman |
2015-06-20 11:01:47 | ncoghlan | set | messageid: <1434798107.27.0.0357174570272.issue19979@psf.upfronthosting.co.za> |
2015-06-20 11:01:47 | ncoghlan | link | issue19979 messages |
2015-06-20 11:01:46 | ncoghlan | create | |
|