[Python-Dev] return type of __complex__

Mark Dickinson dickinsm at gmail.com
Fri Oct 19 18:41:25 CEST 2012


On Fri, Oct 19, 2012 at 5:31 PM, Christian Heimes <christian at python.org> wrote:
> In order to fix the bug the code in PyComplex_AsCComplex() must be
> altered to support float as return type from __complex__(). That's a
> major change.

Agreed that this doesn't seem appropriate for bugfix releases.

We might also want to consider having PyComplex_AsCComplex check for
__float__, again for consistency with the 'complex' constructor:

>>> class A(object):
...     def __float__(self):
...         return 42.0
...
>>> a = A()
>>> float(a)
42.0
>>> complex(a)
(42+0j)

Mark


More information about the Python-Dev mailing list