IronLanguages / ironpython3

Implementation of Python 3.x for .NET Framework that is built on top of the Dynamic Language Runtime.
Apache License 2.0
2.49k stars 288 forks source link

PEP 424 -- A method for exposing a length hint #6

Open jdhardy opened 10 years ago

jdhardy commented 10 years ago

http://www.python.org/dev/peps/pep-0424/

rtzoeller commented 6 years ago

It looks like itertools.repeat, list_iterator, list_reverseiterator, dict_keyiterator, and reversed all currently implement __length_hint__(), and the current version of the standard library includes operator.length_hint().

Can this issue be closed? It does not look like we currently make use of the __length_hint__ anywhere; do we want to investigate any potential performance gains from using this information? E.g. the following Python code does not allocate the correct size backing array, but could.

list(iter([1,2,3,4,5]))
slozier commented 6 years ago

I'd like to get most of test_iterlen passing before this one is closed. For example, the following don't have length hints: rangeiterator (which should be renamed to range_iterator), tupleiterator (which should be renamed to range_iterator), deque_iterator and so on.