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 brandtbucher
Recipients brandtbucher, gregory.p.smith, twouters
Date 2020-10-28.19:58:25
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1603915106.04.0.275659771807.issue42185@roundup.psfhosted.org>
In-reply-to
Content
Hm, I believe it is related to the reason why we need to use LOAD_CLASSDEREF instead of LOAD_DEREF with nonlocal names in class scope. If I understand correctly, the purpose is to keep nonlocal statements in methods from referencing class-level names.

From https://docs.python.org/3/reference/executionmodel.html#resolution-of-names:

> Class definition blocks and arguments to exec() and eval() are special in the context of name resolution. A class definition is an executable statement that may use and define names. These references follow the normal rules for name resolution with an exception that unbound local variables are looked up in the global namespace. The namespace of the class definition becomes the attribute dictionary of the class. The scope of names defined in a class block is limited to the class block; it does not extend to the code blocks of methods – this includes comprehensions and generator expressions since they are implemented using a function scope. This means that the following will fail:
> 
> class A:
>     a = 42
>     b = list(a + i for i in range(10))
History
Date User Action Args
2020-10-28 19:58:26brandtbuchersetrecipients: + brandtbucher, twouters, gregory.p.smith
2020-10-28 19:58:26brandtbuchersetmessageid: <1603915106.04.0.275659771807.issue42185@roundup.psfhosted.org>
2020-10-28 19:58:26brandtbucherlinkissue42185 messages
2020-10-28 19:58:25brandtbuchercreate