[issue37040] checking for membership in itertools.count enters infinite loop with no way to exit

Dan Rose report at bugs.python.org
Sat May 25 13:30:58 EDT 2019


Dan Rose <daniel.buchoff at gmail.com> added the comment:

The general problem with infinite iterators is indeed a bigger issue and its resolution would probably resolve this issue too. With the examples you gave at least the user can ctrl-c to interrupt. Entering an infinite, *uninterruptible* loop is a consequence so bad that it deserves a guard rail.

> On May 25, 2019, at 11:48, Serhiy Storchaka <report at bugs.python.org> wrote:
> 
> 
> Serhiy Storchaka <storchaka+cpython at gmail.com> added the comment:
> 
> Adding the __contains__() method to the count iterator would not solve the general problem with infinite iterators. For example with the following expressions:
> 
>    -1 in filter(None, itertools.count())
>    -1 in map(float, itertools.count())
> 
> It is not worth to add a method just to handle a single case of misusing. You should not use "in" with infinite iterators.
> 
> ----------
> nosy: +serhiy.storchaka
> 
> _______________________________________
> Python tracker <report at bugs.python.org>
> <https://bugs.python.org/issue37040>
> _______________________________________

----------

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


More information about the Python-bugs-list mailing list