Skip to content

Commit a9c1cda

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

File tree

3 files changed

+18
-0
lines changed

3 files changed

+18
-0
lines changed

doc/whatsnew/fragments/7828.bugfix

+3
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

+5
Original file line numberDiff line numberDiff line change
@@ -1135,6 +1135,11 @@ def _looks_like_infinite_iterator(param: nodes.NodeNG) -> bool:
11351135
# A next() method, which is now what we want.
11361136
return
11371137

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

11401145
if (

tests/functional/s/stop_iteration_inside_generator.py

+10
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)