[Python-Dev] PEP 0424: A method for exposing a length hint

Steven D'Aprano steve at pearwood.info
Sun Jul 15 15:47:07 CEST 2012


Antoine Pitrou wrote:

> The point is that 0 is a legitimate value for a length hint. Simple
> implementations of __length_hint__ will start returning 0 as a
> legitimate value and you will wrongly interpret that as "don't know",
> which kinds of defeat the purpose of __length-hint__  ;) 

> That said, I don't think a special value for "is infinite" is useful.
> Just make -1 mean "I don't know".

You've obviously never accidentally called list on an infinite iterator *wink*

It's not the (eventual) MemoryError that is the problem. On some systems, this 
can cause the PC  to become unresponsive as the OS tries to free an 
ever-increasing amount of memory. Been there, done that, on a production 
system. I had to do a hard reboot to fix it.

I think having a hint that says "there's no way this can succeed, fail 
immediately" is more useful than caring about the difference between a hint of 
0 and a hint of 1.



-- 
Steven


More information about the Python-Dev mailing list