This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author mark.dickinson
Recipients mark.dickinson
Date 2012-10-20.09:39:39
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <>
See thread starting at

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:39mark.dickinsonsetrecipients: + mark.dickinson
2012-10-20 09:39:39mark.dickinsonsetmessageid: <>
2012-10-20 09:39:39mark.dickinsonlinkissue16290 messages
2012-10-20 09:39:39mark.dickinsoncreate