
On Sun, 18 Apr 2021, 1:59 am Jelle Zijlstra, <jelle.zijlstra@gmail.com> wrote:
El sáb, 17 abr 2021 a las 8:30, Nick Coghlan (<ncoghlan@gmail.com>) escribió:.
Metaclass __prepare__ methods can inject names into the class namespace that the compiler doesn't know about, so yeah, it unfortunately has to be conservative and use LOAD_NAME in class level code.
But of course, most metaclasses don't. I wonder if there are cases where
the compiler can statically figure out that there are no metaclass shenanigans going on, and emit LOAD_GLOBAL anyway. It seems safe at least when the class has no base classes and no metaclass=.
Aye, that particular case is one the symtable pass could at least theoretically identify. As soon as there is a name to resolve in the class header, though, it's no longer safe for the compiler to make assumptions :( Cheers, Nick.