[Numpy-discussion] Curious behavior of __radd__

Andreas Kloeckner lists at informa.tiker.net
Wed Feb 1 14:26:43 EST 2012


Hi all,

here's something I don't understand. Consider the following code snippet:

---------------------------------------------------
class A(object):
    def __radd__(self, other):
        print(type(other))

import numpy as np
np.complex64(1j) + A()
---------------------------------------------------

In my world, this should print <type 'numpy.complex64'>.
It does print <type 'complex'>.

Who is casting my sized complex to a built-in complex, and why?

It can be Python's type coercion, because the behavior is the same in
Python 3.2. (And the docs say Python 3 doesn't support coercion.)

(Please cc me.)

Thanks,
Andreas
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 189 bytes
Desc: not available
URL: <http://mail.python.org/pipermail/numpy-discussion/attachments/20120201/0a18132b/attachment.sig>


More information about the NumPy-Discussion mailing list