[Python-Dev] return type of __complex__

Antonio Cuni anto.cuni at gmail.com
Fri Oct 19 17:15:42 CEST 2012


On 10/19/2012 04:13 PM, Nick Coghlan wrote:
> On Fri, Oct 19, 2012 at 11:08 PM, Antonio Cuni <anto.cuni at gmail.com> wrote:
>> Is that the real intended behavior?
> 
> Given the way complex numbers interact with floats generally,
> returning a complex number with no imaginary component as a floating
> point value seems legitimate and the checks in cmath overly strict.
> Otherwise you would get redundancy like:
> 
>     def __complex__(self):
>         return complex(value)
> 
> or
> 
>     def __complex__(self):
>         return value + 0j
> 
> More importantly, relaxing the checks in cmath is backwards
> compatible. while tightening up the checks in complex_new is not.

indeed, you are right. So I suppose that in pypy we could just relax the check
in cmath and be happy. Is there any chance that this will be changed in 2.7
and/or 3.x?

ciao,
Anto



More information about the Python-Dev mailing list