Skip to content

Commit

Permalink
do not cras if next()` is called
Browse files Browse the repository at this point in the history
  • Loading branch information
clavedeluna committed Nov 23, 2022
1 parent 694d302 commit 7f373b9
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 0 deletions.
3 changes: 3 additions & 0 deletions doc/whatsnew/fragments/7828.bugfix
@@ -0,0 +1,3 @@
Fixes a crash during ``stop-iteration-return`` if builtin ``next`` is called without arguments.

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

if len(node.args) == 0:
# builtin next method should never be called without args.
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 7f373b9

Please sign in to comment.