[issue33939] Raise TypeError in __length_hint__ for consistently infinite iterators

2018-06-22 Thread Erik Bray
Erik Bray added the comment: Per the discussion in https://trac.sagemath.org/ticket/24757, it would also be nice if some other common iterables like map and filter implemented a similar __length_hint__ which would interrogate whatever iterables were give as their argument(s). To summarize

[issue33939] Raise TypeError in __length_hint__ for consistently infinite iterators

2018-06-22 Thread Jeroen Demeyer
Jeroen Demeyer added the comment: By the way, there is a precedent for OverflowError on infinities: >>> import math >>> int(math.inf) Traceback (most recent call last): File "", line 1, in OverflowError: cannot convert float infinity to integer --

[issue33939] Raise TypeError in __length_hint__ for consistently infinite iterators

2018-06-22 Thread Jeroen Demeyer
Jeroen Demeyer added the comment: I'm certainly in favor of adding a way for infinite iterators to state that they are infinite. I just feel like TypeError is way overused in Python. I also disagree that it's a category error: it's an iterable, so it does make sense to ask for its length.

[issue33939] Raise TypeError in __length_hint__ for consistently infinite iterators

2018-06-22 Thread Nick Coghlan
Nick Coghlan 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

[issue33939] Raise TypeError in __length_hint__ for consistently infinite iterators

2018-06-22 Thread Jeroen Demeyer
Jeroen Demeyer added the comment: Why TypeError? Wouldn't OverflowError be more suitable? -- nosy: +jdemeyer ___ Python tracker ___

[issue33939] Raise TypeError in __length_hint__ for consistently infinite iterators

2018-06-22 Thread Nick Coghlan
New submission from Nick Coghlan : This is a simpler proposal born out of https://bugs.python.org/issue31815: adding __length_hint__ implementations to some known-infinite iterators in itertools that always raise TypeError. This means that iterator consumers that use the