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 ncoghlan
Recipients arigo, ethan.furman, ncoghlan, terry.reedy
Date 2015-06-20.11:01:46
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1434798107.27.0.0357174570272.issue19979@psf.upfronthosting.co.za>
In-reply-to
Content
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".
History
Date User Action Args
2015-06-20 11:01:47ncoghlansetrecipients: + ncoghlan, arigo, terry.reedy, ethan.furman
2015-06-20 11:01:47ncoghlansetmessageid: <1434798107.27.0.0357174570272.issue19979@psf.upfronthosting.co.za>
2015-06-20 11:01:47ncoghlanlinkissue19979 messages
2015-06-20 11:01:46ncoghlancreate