[Python-Dev] PEP 3135 (new super()) __class__ references broken in 3.3

Nick Coghlan ncoghlan at gmail.com
Sun May 20 10:51:27 CEST 2012


PEP 3135 defines the new zero-argument form of super() as implicitly
equivalent to super(__class__, <first argument>), 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:
1. Revert the previous fix for #12370
2. Add tests for direct access to __class__ from methods
3. 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


More information about the Python-Dev mailing list