[issue16290] PyComplex_AsCComplex should allow __complex__ to return float.

Serhiy Storchaka report at bugs.python.org
Sat Oct 20 14:41:13 CEST 2012


Serhiy Storchaka added the comment:

> My interpretation of that is that __int__ should return an int, __float__ a
> float, __complex__ a complex number; 

It's a reasonable interpretation. Changing it can be confusing.

On the other hand, int and float look like specialized subclasses of complex 
(they even have .real, .imag and .conjugate()). The ducktype principle 
requires that we can use ints or floats everywhere where complexes needed. This 
means that you should add a branch for integers too.

----------

_______________________________________
Python tracker <report at bugs.python.org>
<http://bugs.python.org/issue16290>
_______________________________________


More information about the Python-bugs-list mailing list