[Python-ideas] Allow __len__ to return infinity

Ethan Furman ethan at stoneleaf.us
Wed Feb 26 00:47:24 CET 2014


On 02/25/2014 03:40 PM, Greg Ewing wrote:
> Steven D'Aprano wrote:
>> (1) __len__ can return *any* float, regardless of value, including lengths of 0.5, NAN, 1e300, etc. This is
>> undesirable because lengths of sequences should be positive or zero whole numbers,
>
> What about things other than sequences?
>
> For a vector type, for example, it would make sense
> for len(v) to return the magnitude of the vector.

Very good point.  To which I reply:  singledispatch !  ;)

http://docs.python.org/dev/whatsnew/3.4.html#whatsnew-singledispatch

--
~Ethan~


More information about the Python-ideas mailing list