[Python-Dev] PEP 0424: A method for exposing a length hint
Ethan Furman
ethan at stoneleaf.us
Mon Jul 16 21:59:20 CEST 2012
M Stefan wrote:
> Also, what would iter([1,2,3]).__length_hint__() return? 3 or unknown?
> If 3, then the semantics of l=[1,2,3]; l += iter(l) will change
> (infinite loop without __length_hint__ vs. list of 6 elements with __length_hint__).
What __length_hint__ returns is irrelevant -- it's only a hint. Python
will have to loop over all the items. So you would still get an
infinite loop with the above code.
~Ethan~
More information about the Python-Dev
mailing list