Skip to content

Commit

Permalink
Do not crash if next() is called without arguments (#7831)
Browse files Browse the repository at this point in the history
Co-authored-by: Pierre Sassoulas <pierre.sassoulas@gmail.com>
(cherry picked from commit a9c1cda)
  • Loading branch information
clavedeluna authored and github-actions[bot] committed Nov 24, 2022
1 parent ac2da87 commit 0b6edd2
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 0 deletions.
3 changes: 3 additions & 0 deletions doc/whatsnew/fragments/7828.bugfix
@@ -0,0 +1,3 @@
Fixes a crash in ``stop-iteration-return`` when the ``next`` builtin is called without arguments.

Closes #7828
5 changes: 5 additions & 0 deletions pylint/checkers/refactoring/refactoring_checker.py
Expand Up @@ -1134,6 +1134,11 @@ def _looks_like_infinite_iterator(param: nodes.NodeNG) -> bool:
# A next() method, which is now what we want.
return

if len(node.args) == 0:
# handle case when builtin.next is called without args.
# see https://github.com/PyCQA/pylint/issues/7828
return

inferred = utils.safe_infer(node.func)

if (
Expand Down
10 changes: 10 additions & 0 deletions tests/functional/s/stop_iteration_inside_generator.py
Expand Up @@ -175,3 +175,13 @@ def next(*things):
it = iter(it)
while True:
yield next(1, 2)

def data(filename):
"""
Ensure pylint doesn't crash if `next` is incorrectly called without args
See https://github.com/PyCQA/pylint/issues/7828
"""
with open(filename, encoding="utf8") as file:
next() # attempt to skip header but this is incorrect code
for line in file:
yield line

0 comments on commit 0b6edd2

Please sign in to comment.