Message171832
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> |
|
Date |
User |
Action |
Args |
2012-10-02 21:23:28 | Mark.Shannon | set | recipients:
+ 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:28 | Mark.Shannon | set | messageid: <1349213008.01.0.972418718258.issue12370@psf.upfronthosting.co.za> |
2012-10-02 21:23:27 | Mark.Shannon | link | issue12370 messages |
2012-10-02 21:23:27 | Mark.Shannon | create | |
|