[issue33939] Raise TypeError in __length_hint__ for consistently infinite iterators

Nick Coghlan report at bugs.python.org
Fri Jun 22 09:25:45 EDT 2018


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

OverflowError covers cases like greater-than-sys.maxsize range instances, where the object itself is conceptually finite, but the length can't be represented as a C integer.

This case is different: it's a category error where the question being asked doesn't even make sense for the affected type.

However, unlike len(), where a missing __len__() implementation inherently raises TypeError, backwards compatibility requires operator.length_hint() to handle a missing implementation __length_hint__ implementation as equivalent to an implementation that returns a length hint of 0.

----------

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


More information about the Python-bugs-list mailing list