Nick Coghlan added the comment: OK, I think I have a way to fix this that will actually *reduce* the level of special casing needed in the compiler.
Specifically, I think we may be able to make the class statement emit *two* scopes, rather than the current one. The outer scope would be created with MAKE_CLOSURE, and thus names defined there would participate in lexical scoping. The inner scope would use the current MAKE_FUNCTION behaviour, and thus names defined there would be ignored by lexical scoping. "__class__" would then be defined in the outer scope *after* the class has been created. It would roughly like the following, except with __qualname__ still set correctly: >>> def outer(): ... class inner: ... def method(self): ... print(the_class) ... the_class = inner ... return inner ... >>> cls = outer() >>> cls.method() Traceback (most recent call last): File "<stdin>", line 1, in <module> TypeError: method() missing 1 required positional argument: 'self' >>> cls().method() <class '__main__.outer.<locals>.inner'> The one potential wrinkle I see is whether this might cause a semantic change for name references from the class body to a containing function, but I think the technique is at least worth trying. If this works, __class__ would just become a completely ordinary cell reference, and override it at class scope should work again. super() itself would still need magic to handle the automatic lookup of the first positional argument to the calling function, but at least the symtable magic should be able to go away. ---------- _______________________________________ Python tracker <rep...@bugs.python.org> <http://bugs.python.org/issue12370> _______________________________________ _______________________________________________ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com