Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Do not crash if next() is called without arguments #7831

Merged
merged 1 commit into from Nov 24, 2022
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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 @@ -1135,6 +1135,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