M
Mark Dickinson
I was a little surprised by the following behaviour:
Python 2.5 (r25, Oct 30 2006, 20:50:32)
[GCC 4.0.1 (Apple Computer, Inc. build 5363)] on darwin
Type "help", "copyright", "credits" or "license" for more information..... def __float__(self): return 10.0
........ def __complex__(self): return 10+0j
....Traceback (most recent call last):
File "<stdin>", line 1, in <module>
TypeError: a float is required
Having recently made the pleasant discovery that math.sqrt and friends
will happily accept any object with a working __float__ attribute, I
expected the same to be true with regards to cmath and __complex__.
The bit that I find really counter-intuitive is that the cmath
functions will use __float__ if available, but completely ignore
__complex__.
Does anyone know of a good reason for the above behaviour? Would a
patch to complexobject.c that `fixes' this be of any interest to
anyone but me? Or would it likely break something else?
Mark
Python 2.5 (r25, Oct 30 2006, 20:50:32)
[GCC 4.0.1 (Apple Computer, Inc. build 5363)] on darwin
Type "help", "copyright", "credits" or "license" for more information..... def __float__(self): return 10.0
........ def __complex__(self): return 10+0j
....Traceback (most recent call last):
File "<stdin>", line 1, in <module>
TypeError: a float is required
Having recently made the pleasant discovery that math.sqrt and friends
will happily accept any object with a working __float__ attribute, I
expected the same to be true with regards to cmath and __complex__.
The bit that I find really counter-intuitive is that the cmath
functions will use __float__ if available, but completely ignore
__complex__.
Does anyone know of a good reason for the above behaviour? Would a
patch to complexobject.c that `fixes' this be of any interest to
anyone but me? Or would it likely break something else?
Mark