[Python-Dev] Do we need __length_hint__ at all? (Was PEP 0424: A method for exposing a length hint)

Antoine Pitrou solipsis at pitrou.net
Mon Jul 16 16:01:54 CEST 2012

On Mon, 16 Jul 2012 23:23:18 +1000
Nick Coghlan <ncoghlan at gmail.com> wrote:
> - distinguishing between different reasons for saying "don't
> preallocate any space" (i.e. returning zero). I still haven't heard a
> convincing rationale for this one

The point is that zero is a valid value for a length hint. By making it
a special value for "don't know", you are making the protocol
potentially confusing, and you are also departing from the current

(and, yes, I think distinguishing between zero and "don't know" is
useful: imagine a container that would preallocate 256 entries by
default when the answer is "don't know")

> The PEP itself already has this general tone, but I think that it
> should be even more emphatic that it's about codifying the status quo,
> *not* about modifying it with ideas haven't been proven useful through
> past experience.

Then the PEP shouldn't address infinite iterators at all.



Software development and contracting: http://pro.pitrou.net

More information about the Python-Dev mailing list