Author gumtree
Recipients gumtree, mark.dickinson, meador.inge
Date 2010-11-26.03:45:04
SpamBayes Score 0.000303858
Marked as misclassified No
Message-id <AANLkTi=gptvwN_-vAkwdfMxQtiyXE-=O5mpDktzN+s3N@mail.gmail.com>
In-reply-to
Content
Hi Mark,

I thought that this had all been fixed, but it seems not.

Consider the following:

class xcomplex( complex ):
    def __new__(cls,*args,**kwargs):
        return complex.__new__(cls,*args,**kwargs)
    def __add__(self,x):
        return xcomplex( complex.__add__(self,x) )
    def __radd__(self,x):
        print "larg: ", type(x),"returning: ",
        return xcomplex( complex.__radd__(self,x) )

class xfloat(float):
    def __new__(cls,*args,**kwargs):
        return float.__new__(cls,*args,**kwargs)
    def __add__(self,x):
        return xfloat( float.__add__(self,x) )
    def __radd__(self,x):
        print "larg: ", type(x),"returning: ",
        return xfloat( float.__radd__(self,x) )

z = 1j
xz = xcomplex(1j)
f = 1.0
xf = xfloat(1.0)

print
print "-----------"
print "expect xcomplex:", type(z + xz)
print "expect xcomplex:", type(f + xz)
print "expect xfloat:", type(f + xf)
print "expect ???:", type(z + xf)

When this runs, the first three conversions are fine, the last is not: there
is no call to xfloat.__radd__. It seems that the builtin complex type simply
thinks it is dealing with a float. Here is the output

-----------
expect xcomplex: larg:  <type 'complex'> returning:  <class
'__main__.xcomplex'>
expect xcomplex: larg:  <type 'float'> returning:  <class
'__main__.xcomplex'>
expect xfloat: larg:  <type 'float'> returning:  <class '__main__.xfloat'>
expect ???: <type 'complex'>

The last line shows that no call to __radd__ occurred.

Is there anything that can be done now about this now, or is it just too
late?

Regards

Blair

At 01:13 a.m. 31/05/2010, you wrote:

Mark Dickinson <dickinsm@gmail.com> added the comment:

r78280 didn't remove the implicit coercion for rich comparisons;  that's now
been done in r81606.

----------

_______________________________________
Python tracker <report@bugs.python.org>
<http://bugs.python.org/issue5211>
_______________________________________Python tracker <
report@bugs.python.org>
Files
File name Uploaded
unnamed gumtree, 2010-11-26.03:45:04
History
Date User Action Args
2010-11-26 03:45:06gumtreesetrecipients: + gumtree, mark.dickinson, meador.inge
2010-11-26 03:45:04gumtreelinkissue5211 messages
2010-11-26 03:45:04gumtreecreate