[issue19979] Missing nested scope vars in class scope (bis)
Nick Coghlan
report at bugs.python.org
Sat Jun 20 13:01:47 CEST 2015
Nick Coghlan added the comment:
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".
----------
nosy: +ncoghlan
_______________________________________
Python tracker <report at bugs.python.org>
<http://bugs.python.org/issue19979>
_______________________________________
More information about the Python-bugs-list
mailing list