classification
Title: Direct access to lexically scoped __class__ is broken in 3.3
Type: behavior Stage: resolved
Components: Versions: Python 3.3
process
Status: closed Resolution: fixed
Dependencies: Superseder:
Assigned To: Nosy List: Arfrever, daniel.urban, meador.inge, ncoghlan, python-dev
Priority: release blocker Keywords: 3.2regression

Created on 2012-05-19 14:52 by ncoghlan, last changed 2012-05-27 08:17 by python-dev. This issue is now closed.

Messages (3)
msg161126 - (view) Author: Nick Coghlan (ncoghlan) * (Python committer) Date: 2012-05-19 14:52
Currently, __class__ references from methods in 3.3 aren't being mapped correctly to the class currently being defined.

This goes against the documented behaviour of PEP 3135, which states explicitly that the new zero-argument form is equivalent to super(__class__, <firstarg>), where __class__ is the closure reference.

This breakage is almost certainly due to the fix for #12370

The fact the test suite didn't break is a sign we also have a gap in our test coverage.

Given that a workaround is documented in #12370, but there's no workaround for this breakage, reverting the fix for that issue may prove necessary (unlike that current breakage, at least that wouldn't be a regression from 3.2).
msg161215 - (view) Author: Meador Inge (meador.inge) * (Python committer) Date: 2012-05-20 16:12
Ouch.  The '__class__' behavior is documented here too: http://docs.python.org/py3k/library/functions.html?highlight=__class__#super.  Unfortunately I don't see any other documentation on the lexically scoped form of __class__.

As implied, cases like the following just don't work any longer:

>>> class X(object):
...    def __init__(self):
...       super(__class__, self).__init__()
... 
>>> X()
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "<stdin>", line 3, in __init__
NameError: global name '__class__' is not defined

This worked fine in 3.2.
msg161702 - (view) Author: Roundup Robot (python-dev) Date: 2012-05-27 08:17
New changeset bcb3b81853cc by Nick Coghlan in branch 'default':
Tweak importlib._bootstrap to avoid zero-argument super so I can work on issue #14857 without breaking imports
http://hg.python.org/cpython/rev/bcb3b81853cc

New changeset 96ab78ef82a7 by Nick Coghlan in branch 'default':
Close #14857: fix regression in references to PEP 3135 implicit __class__ closure variable. Reopens issue #12370, but also updates unittest.mock to workaround that issue
http://hg.python.org/cpython/rev/96ab78ef82a7
History
Date User Action Args
2012-05-27 08:17:22python-devsetstatus: open -> closed

nosy: + python-dev
messages: + msg161702

resolution: fixed
stage: test needed -> resolved
2012-05-20 16:12:59meador.ingesetnosy: + meador.inge
messages: + msg161215
2012-05-20 14:32:44Arfreversetnosy: + Arfrever
2012-05-20 09:27:36daniel.urbansetnosy: + daniel.urban
2012-05-19 14:52:09ncoghlancreate