[issue33939] Raise OverflowError in __length_hint__ for consistently infinite iterators

Nick Coghlan report at bugs.python.org
Fri Jun 22 11:25:16 EDT 2018


Nick Coghlan <ncoghlan at gmail.com> added the comment:

Using OverflowError wouldn't mean "I'm infinite", it would only mean "I'm larger than sys.maxsize" (the same way it does for range objects).

However, it may be that that's fine, since the information we really want to convey is:

1. Trying to store this iterable in memory would be a really bad idea
2. Even trying to iterate over this iterable to the end would probably also be a bad idea

And OverflowError conveys those pragmatic consequences pretty well.

(Returning math.inf isn't an option, since __length_hint__ is specified as returning an integer: https://www.python.org/dev/peps/pep-0424/)

----------
title: Raise TypeError in __length_hint__ for consistently infinite iterators -> Raise OverflowError in __length_hint__ for consistently infinite iterators

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


More information about the Python-bugs-list mailing list