diff options
author | Dani Alcala <112832187+clavedeluna@users.noreply.github.com> | 2022-11-24 17:51:04 -0300 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-11-24 21:51:04 +0100 |
commit | a9c1cdabd6d55b6df86b7aef5779f7fc308a3d1c (patch) | |
tree | 26cacf516ab08cd07574b0ea69e9c7d449d74af2 | |
parent | 15733b4c8117e19e57e60a003e693ca2a5c494a7 (diff) | |
download | pylint-git-a9c1cdabd6d55b6df86b7aef5779f7fc308a3d1c.tar.gz |
Do not crash if next() is called without arguments (#7831)
Co-authored-by: Pierre Sassoulas <pierre.sassoulas@gmail.com>
-rw-r--r-- | doc/whatsnew/fragments/7828.bugfix | 3 | ||||
-rw-r--r-- | pylint/checkers/refactoring/refactoring_checker.py | 5 | ||||
-rw-r--r-- | tests/functional/s/stop_iteration_inside_generator.py | 10 |
3 files changed, 18 insertions, 0 deletions
diff --git a/doc/whatsnew/fragments/7828.bugfix b/doc/whatsnew/fragments/7828.bugfix new file mode 100644 index 000000000..f47cc3cc9 --- /dev/null +++ b/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 diff --git a/pylint/checkers/refactoring/refactoring_checker.py b/pylint/checkers/refactoring/refactoring_checker.py index ec68099a6..9cc316649 100644 --- a/pylint/checkers/refactoring/refactoring_checker.py +++ b/pylint/checkers/refactoring/refactoring_checker.py @@ -1135,6 +1135,11 @@ class RefactoringChecker(checkers.BaseTokenChecker): # 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 ( diff --git a/tests/functional/s/stop_iteration_inside_generator.py b/tests/functional/s/stop_iteration_inside_generator.py index a143fd946..efde61a77 100644 --- a/tests/functional/s/stop_iteration_inside_generator.py +++ b/tests/functional/s/stop_iteration_inside_generator.py @@ -175,3 +175,13 @@ def other_safeiter(it): 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 |