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

2019-05-31 Thread Terry J. Reedy


Terry J. Reedy  added the comment:

Dan, please leave this closed.  It duplicates #31815 and should be closed on 
that grounds alone, regardless of the status of the latter.  #31815 was closed 
in favor of #33939, which is open, with ongoing discussion.  Resolution either 
way is blocked because different core developers disagree.

--
nosy: +terry.reedy
resolution:  -> duplicate
status: open -> closed
superseder:  -> Make itertools iterators interruptible

___
Python tracker 

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



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

2019-05-27 Thread Jeffrey Kintscher


Change by Jeffrey Kintscher :


--
nosy: +Jeffrey.Kintscher

___
Python tracker 

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



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

2019-05-25 Thread Dan Rose


Dan Rose  added the comment:

Oops you are right. These enter uninterruptible loops too. They are exceptional 
situations and should do the expected thing - throw exceptions as well.

--

___
Python tracker 

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



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

2019-05-25 Thread Serhiy Storchaka


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

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



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

2019-05-25 Thread Dan Rose


Dan Rose  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  wrote:
> 
> 
> Serhiy Storchaka  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 
> 
> ___

--

___
Python tracker 

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



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

2019-05-25 Thread SilentGhost


Change by SilentGhost :


--
nosy:  -SilentGhost

___
Python tracker 

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



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

2019-05-25 Thread Dan Rose


Dan Rose  added the comment:

Reopening. While my behavioral expectation may be wrong, the current behavior 
is inappropriate. It would make more sense for count to have a `__contains__` 
method which raises a TypeError.

--
resolution: rejected -> 
status: closed -> open

___
Python tracker 

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



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

2019-05-25 Thread Martin Panter


Martin Panter  added the comment:

Problems with long-running iterators are already discussed in:

Issue 31815: rejected proposal to check for interrupts
Issue 33939: proposal to flag iterators as being infinite

--
nosy: +martin.panter

___
Python tracker 

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



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

2019-05-24 Thread SilentGhost


SilentGhost  added the comment:

This seem like a misdirected expectation. count returns a regular iterator and 
the purpose behind it is not to enable membership checks, this only works 
because it's a regular iterators and normal rules for checking membership are 
applied.

In any case, it is possible to write an infinite loop in Python either by 
accident or intentionally, this doesn't seem like a reasonable rationale for 
making this sort changes.

--
nosy: +SilentGhost, rhettinger
resolution:  -> rejected
stage:  -> resolved
status: open -> closed
type:  -> behavior
versions: +Python 3.8 -Python 3.7

___
Python tracker 

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



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

2019-05-24 Thread Dan Rose


New submission from Dan Rose :

Checking membership in `itertools.count()` will either return True in linear 
time or enter an infinite loop that cannot be terminated with Ctrl-c. This

```
import itertools
1 in itertools.count(0,2)
```

It is expected that the above code will use an efficient (O(1)) membership 
algorithm like range objects.

--
components: Library (Lib)
messages: 343452
nosy: Dan Rose
priority: normal
severity: normal
status: open
title: checking for membership in itertools.count enters infinite loop with no 
way to exit
versions: Python 3.7

___
Python tracker 

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