[issue5211] Fix complex type to avoid coercion in 2.7.

Mark Dickinson report at bugs.python.org
Fri Nov 26 14:12:35 CET 2010


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

I think that's expected behaviour.  Note that int vs float behaves in the same way as float vs complex:

>>> class xint(int):
...     def __radd__(self, other):
...         print "__radd__"
...         return 42
... 
>>> 3 + xint(5)
__radd__
42
>>> 3.0 + xint(5)  # xint.__radd__ not called.
8.0

As with your example, the float.__add__ method is happy to deal with an int or an instance of any subclass of int.

----------

_______________________________________
Python tracker <report at bugs.python.org>
<http://bugs.python.org/issue5211>
_______________________________________


More information about the Python-bugs-list mailing list