Mark Shannon added the comment:

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>

----------

_______________________________________
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

Reply via email to