Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

stop-iteration-return false positive when using itertools.cycle #7765

Closed
richardfearn opened this issue Nov 14, 2022 · 1 comment · Fixed by #7766
Closed

stop-iteration-return false positive when using itertools.cycle #7765

richardfearn opened this issue Nov 14, 2022 · 1 comment · Fixed by #7766
Labels
False Positive 🦟 A message is emitted but nothing is wrong with the code Needs PR This issue is accepted, sufficiently specified and now needs an implementation
Milestone

Comments

@richardfearn
Copy link

richardfearn commented Nov 14, 2022

Bug description

Running pylint on this code gives a false positive:

from itertools import cycle


def test():
    vals = cycle('ABCD')
    while True:
        yield next(vals)

This is similar to #2158 which was fixed by adding a list of known infinite iterators.

Configuration

No response

Command used

pylint test.py

Pylint output

************* Module test
test.py:7:14: R1708: Do not raise StopIteration in generator, use return statement instead (stop-iteration-return)

Expected behavior

No warning, because cycle repeats indefinitely.

Pylint version

pylint 2.12.2
astroid 2.9.3
Python 3.10.7 (main, Nov  2 2022, 18:49:29) [GCC 12.2.0]

OS / Environment

Ubuntu 22.10

Additional dependencies

No response

@richardfearn richardfearn added the Needs triage 📥 Just created, needs acknowledgment, triage, and proper labelling label Nov 14, 2022
@Pierre-Sassoulas Pierre-Sassoulas added False Positive 🦟 A message is emitted but nothing is wrong with the code Needs investigation 🔬 A bug or crash where it's not immediately obvious what is happenning and removed Needs triage 📥 Just created, needs acknowledgment, triage, and proper labelling labels Nov 14, 2022
@Pierre-Sassoulas Pierre-Sassoulas added Needs PR This issue is accepted, sufficiently specified and now needs an implementation and removed Needs investigation 🔬 A bug or crash where it's not immediately obvious what is happenning labels Nov 14, 2022
@Pierre-Sassoulas Pierre-Sassoulas added this to the 2.15.6 milestone Nov 14, 2022
@richardfearn
Copy link
Author

Thanks for the quick fix!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
False Positive 🦟 A message is emitted but nothing is wrong with the code Needs PR This issue is accepted, sufficiently specified and now needs an implementation
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants