Nick Coghlan writes:

 > Right, I agree on the value in being able to return something to say "this
 > cannot be converted to a concrete container".
 > 
 > I still haven't seen a use case where the appropriate response to "I don't
 > know" differs from the appropriate response to a hint of zero - that is,
 > you don't preallocate, you just start iterating.

Why wouldn't one just believe the hint and jump past the iteration?

What about an alternative API such as length_hint(iter, bound)
returning 'cannot say' (if no hint is available), 'small' (if the
estimated length is less than bound), and 'large' (if it's greater
than the bound or infinite)?  (Or None, True, False which would give
the boolean interpretation "do I know I'm small enough to be converted
to a concrete container?")

The point is that I don't really see the value in returning a precise
estimate that cannot be relied on to be accurate.  OK, Python is a
"consenting adults" language, but returning an integer here seems like
invitation to abuse.
_______________________________________________
Python-Dev mailing list
Python-Dev@python.org
http://mail.python.org/mailman/listinfo/python-dev
Unsubscribe: 
http://mail.python.org/mailman/options/python-dev/archive%40mail-archive.com

Reply via email to