Skip to content

Commit 9ec1aa0

Browse files
Do not crash if next() is called without arguments (#7831)
Co-authored-by: Pierre Sassoulas <[email protected]> (cherry picked from commit a9c1cda)
1 parent ac2da87 commit 9ec1aa0

File tree

3 files changed

+18
-0
lines changed

3 files changed

+18
-0
lines changed

doc/whatsnew/fragments/7828.bugfix

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
Fixes a crash in ``stop-iteration-return`` when the ``next`` builtin is called without arguments.
2+
3+
Closes #7828

pylint/checkers/refactoring/refactoring_checker.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1134,6 +1134,11 @@ def _looks_like_infinite_iterator(param: nodes.NodeNG) -> bool:
11341134
# A next() method, which is now what we want.
11351135
return
11361136

1137+
if len(node.args) == 0:
1138+
# handle case when builtin.next is called without args.
1139+
# see https://github.com/PyCQA/pylint/issues/7828
1140+
return
1141+
11371142
inferred = utils.safe_infer(node.func)
11381143

11391144
if (

tests/functional/s/stop_iteration_inside_generator.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -175,3 +175,13 @@ def next(*things):
175175
it = iter(it)
176176
while True:
177177
yield next(1, 2)
178+
179+
def data(filename):
180+
"""
181+
Ensure pylint doesn't crash if `next` is incorrectly called without args
182+
See https://github.com/PyCQA/pylint/issues/7828
183+
"""
184+
with open(filename, encoding="utf8") as file:
185+
next() # attempt to skip header but this is incorrect code
186+
for line in file:
187+
yield line

0 commit comments

Comments
 (0)