Message173379
See thread starting at http://mail.python.org/pipermail/python-dev/2012-October/122241.html
The cmath module functions don't accept custom types that define __complex__, but whose __complex__ method returns a float rather than a complex number:
Python 3.4.0a0 (default:53a7c2226a2b+, Oct 19 2012, 12:16:36)
[GCC 4.2.1 (Apple Inc. build 5664)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> class A:
... def __complex__(self): return 42.0
...
>>> import cmath
>>> cmath.sqrt(A())
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
TypeError: __complex__ should return a complex object
In contrast, the complex constructor is happy to accept such objects.
The root cause is that PyArg_ParseTuple's 'D' format calls PyComplex_AsCComplex (in Objects/complexobject.c), which refuses to accept a __complex__ result of type float. |
|
Date |
User |
Action |
Args |
2012-10-20 09:39:39 | mark.dickinson | set | recipients:
+ mark.dickinson |
2012-10-20 09:39:39 | mark.dickinson | set | messageid: <1350725979.91.0.694424373202.issue16290@psf.upfronthosting.co.za> |
2012-10-20 09:39:39 | mark.dickinson | link | issue16290 messages |
2012-10-20 09:39:39 | mark.dickinson | create | |
|