[New-bugs-announce] [issue33939] Raise TypeError in __length_hint__ for consistently infinite iterators
Nick Coghlan
report at bugs.python.org
Fri Jun 22 08:48:14 EDT 2018
New submission from Nick Coghlan <ncoghlan at gmail.com>:
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 operator.length_hint() API will throw an error when asked to consume them, rather than entering an uninterruptible infinite loop.
The proposed methods added by this proposal would be:
* itertools.count.__length_hint__
* itertools.cycle.__length_hint__
* itertools.repeat.__length_hint__
Each of these would raise TypeError (to indicate an explicitly non-finite length), rather than returning the default of 0 (which length hint API consumers typically interpret as indicating an unknown-but-finite length)
----------
messages: 320229
nosy: ncoghlan, rhettinger
priority: normal
severity: normal
stage: needs patch
status: open
title: Raise TypeError in __length_hint__ for consistently infinite iterators
type: enhancement
versions: Python 3.8
_______________________________________
Python tracker <report at bugs.python.org>
<https://bugs.python.org/issue33939>
_______________________________________
More information about the New-bugs-announce
mailing list