Brandt Bucher <brandtbuc...@gmail.com> added the comment: 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)) ---------- _______________________________________ Python tracker <rep...@bugs.python.org> <https://bugs.python.org/issue42185> _______________________________________ _______________________________________________ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com