Message379840
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)) |
|
Date |
User |
Action |
Args |
2020-10-28 19:58:26 | brandtbucher | set | recipients:
+ brandtbucher, twouters, gregory.p.smith |
2020-10-28 19:58:26 | brandtbucher | set | messageid: <1603915106.04.0.275659771807.issue42185@roundup.psfhosted.org> |
2020-10-28 19:58:26 | brandtbucher | link | issue42185 messages |
2020-10-28 19:58:25 | brandtbucher | create | |
|