Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions doc/whatsnew/fragments/7765.false_positive
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
Don't warn about ``stop-iteration-return`` when using ``next()`` over ``itertools.cycle``.

Closes #7765
2 changes: 1 addition & 1 deletion pylint/checkers/refactoring/refactoring_checker.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@
nodes.TryExcept, nodes.TryFinally, nodes.While, nodes.For, nodes.If
]

KNOWN_INFINITE_ITERATORS = {"itertools.count"}
KNOWN_INFINITE_ITERATORS = {"itertools.count", "itertools.cycle"}
BUILTIN_EXIT_FUNCS = frozenset(("quit", "exit"))
CALLS_THAT_COULD_BE_REPLACED_BY_WITH = frozenset(
(
Expand Down
8 changes: 7 additions & 1 deletion tests/functional/s/stop_iteration_inside_generator.py
Original file line number Diff line number Diff line change
Expand Up @@ -110,14 +110,20 @@ def gen_next_with_sentinel():
yield next([], 42) # No bad return


from itertools import count
from itertools import count, cycle

# https://github.com/PyCQA/pylint/issues/2158
def generator_using_next():
counter = count()
number = next(counter)
yield number * 2

# https://github.com/PyCQA/pylint/issues/7765
def infinite_iterator_itertools_cycle():
counter = cycle('ABCD')
val = next(counter)
yield val


# pylint: disable=too-few-public-methods
class SomeClassWithNext:
Expand Down
2 changes: 1 addition & 1 deletion tests/functional/s/stop_iteration_inside_generator.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,4 @@ stop-iteration-return:44:14:44:21:gen_next_raises_stopiter:Do not raise StopIter
stop-iteration-return:66:18:66:25:gen_next_inside_wrong_try_except:Do not raise StopIteration in generator, use return statement instead:INFERENCE
stop-iteration-return:80:12:80:31:gen_next_inside_wrong_try_except2:Do not raise StopIteration in generator, use return statement instead:INFERENCE
stop-iteration-return:97:18:97:25:gen_dont_crash_on_no_exception:Do not raise StopIteration in generator, use return statement instead:INFERENCE
stop-iteration-return:140:10:140:35:invalid_object_passed_to_next:Do not raise StopIteration in generator, use return statement instead:INFERENCE
stop-iteration-return:146:10:146:35:invalid_object_passed_to_next:Do not raise StopIteration in generator, use return statement instead:INFERENCE