[Python-Dev] PEP 3135 (new super()) class references broken in 3.3 (original) (raw)
Nick Coghlan ncoghlan at gmail.com
Sun May 20 10:51:27 CEST 2012
- Previous message: [Python-Dev] Language reference updated for metaclasses
- Next message: [Python-Dev] PEP 3135 (new super()) __class__ references broken in 3.3
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
PEP 3135 defines the new zero-argument form of super() as implicitly equivalent to super(class, ), and up until 3.2 has behaved accordingly: if you accessed class from inside a method, you would receive a reference to the lexically containing class.
In 3.3, that currently doesn't work: you get NameError instead (http://bugs.python.org/issue14857)
While the 3.2 behaviour wasn't documented in the language reference, it's definitely documented in PEP 3135 (and my recent updates to the 3.3 version of the metaclass docs were written accordingly - that's how I discovered the problem)
The error in the alpha releases appears to be a consequence of the attempt to fix a problem where the special treatment of class meant that you couldn't properly set the class attribute of the class itself in the class body (see http://bugs.python.org/issue12370).
The fact that patch went in without causing a test failure means that this aspect of PEP 3135 has no explicit tests - it was only tested indirectly through the zero-argument super() construct.
What I plan to do:
- Revert the previous fix for #12370
- Add tests for direct access to class from methods
- Create a new fix for #12370 that only affects the class scope, not the method bodies (this will be harder than the previous fix which affected the resolution of class everywhere in the class body).
Cheers, Nick.
-- Nick Coghlan | ncoghlan at gmail.com | Brisbane, Australia
- Previous message: [Python-Dev] Language reference updated for metaclasses
- Next message: [Python-Dev] PEP 3135 (new super()) __class__ references broken in 3.3
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]