[issue33939] Raise OverflowError in __length_hint__ for consistently infinite iterators

2018-06-23 Thread Raymond Hettinger


Raymond Hettinger  added the comment:

Perhaps an object can set an attribute, __infinite_iterator__ = True.

That would provide an unequivocal way to communicate to consumer code that the 
producer is known to generate a non-terminating stream.

--

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue33939] Raise OverflowError in __length_hint__ for consistently infinite iterators

2018-06-23 Thread Serhiy Storchaka


Serhiy Storchaka  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 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue33939] Raise OverflowError in __length_hint__ for consistently infinite iterators

2018-06-22 Thread bbayles


Change by bbayles :


--
nosy: +bbayles

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue33939] Raise OverflowError in __length_hint__ for consistently infinite iterators

2018-06-22 Thread Nick Coghlan


Nick Coghlan  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 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com