This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author Mark.Shannon
Recipients Arfrever, Mark.Shannon, alex, barry, benjamin.peterson, carsten.klein@axn-software.de, cvrebert, daniel.urban, eric.snow, meador.inge, michael.foord, ncoghlan, python-dev
Date 2012-10-02.21:23:26
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1349213008.01.0.972418718258.issue12370@psf.upfronthosting.co.za>
In-reply-to
Content
There seems to be an ongoing confusion about scopes on this thread.

The __class__ variable used by super() is a non-local variable in the scope of any function using super(), whereas the __class__ used to define the type of an object is a class attribute like any other special attribute e.g. __add__.

The cause of the bug is presumably that the (ast-to-bytecode) compiler fails to differentiate the scopes.

See below for (rather ugly) code which correctly implements the example class presented by Micheal.

class X(object):
        
    @property
    def __class__(self):
        return int
        
class Y
    
    def __init__(self):
        super(X, self).__init__()

X.__init__ = Y.__init__
del Y
        
print (isinstance(X(), int))

>>> X.__init__.__code__.co_freevars[0]
'__class__'

>>> X.__dict__['__class__']
<property object at 0x18f5e68>
History
Date User Action Args
2012-10-02 21:23:28Mark.Shannonsetrecipients: + Mark.Shannon, barry, ncoghlan, benjamin.peterson, Arfrever, alex, michael.foord, cvrebert, meador.inge, daniel.urban, carsten.klein@axn-software.de, python-dev, eric.snow
2012-10-02 21:23:28Mark.Shannonsetmessageid: <1349213008.01.0.972418718258.issue12370@psf.upfronthosting.co.za>
2012-10-02 21:23:27Mark.Shannonlinkissue12370 messages
2012-10-02 21:23:27Mark.Shannoncreate