[Python-Dev] return type of complex (original) (raw)

Serhiy Storchaka storchaka at gmail.com
Sun Oct 21 10:26:19 CEST 2012


On 21.10.12 03:15, Antoine Pitrou wrote:

The redundancy sounds like a non-issue to me, since you can implement float instead:

class C: ... def init(self, v): ... self.v = v ... def complex(self): ... return self.v**0.5 ... import cmath cmath.cos(C(-1)) (1.5430806348152437-7.195794243779206e-17j) cmath.cos(C(1)) Traceback (most recent call last): File "", line 1, in TypeError: complex should return a complex object

Returned value can be computed and result can be float or complex depending on values. The author of the class with defined complex() may not even be aware that under certain circumstances he would get a float.

Always write "return complex(...)" is too redundant.



More information about the Python-Dev mailing list