[issue33939] Raise OverflowError in __length_hint__ for consistently infinite iterators

Serhiy Storchaka report at bugs.python.org
Sat Jun 23 03:30:30 EDT 2018


Serhiy Storchaka <storchaka+cpython at gmail.com> added the comment:

See also a meta-issue issue29833.

If use OverflowError as a sign of infinite iterator in __length_hint__, this should be documented as a legitimate use case for OverflowError.

itertools.repeat.__length_hint__() and reversed.__length_hint__() currently raise a TypeError for infinite iterator. reversed.__length_hint__() returns NotImplemented (which raises a TypeError when convert to a C integer). Both TypeError and NotImplemented are handled by the consumer of __length_hint__: in PyObject_LengthHint(). An OverflowError is treated as error.

----------
nosy: +serhiy.storchaka

_______________________________________
Python tracker <report at bugs.python.org>
<https://bugs.python.org/issue33939>
_______________________________________


More information about the Python-bugs-list mailing list