diff options
author | Claudiu Popa <pcmanticore@gmail.com> | 2020-12-29 10:47:23 +0100 |
---|---|---|
committer | Claudiu Popa <pcmanticore@gmail.com> | 2020-12-29 10:47:23 +0100 |
commit | 9a9dbb126c3601bb638f1f195564bcf28c6865dd (patch) | |
tree | 1085e32079cf1766c70223f03e3199ba2014a4fa | |
parent | 17325f2f7c8cf43f7ae61ba6726b5117cc11066c (diff) | |
download | pylint-git-fix-range-without-args-crash.tar.gz |
Fix a crash in `consider-using-enumerate` when encountering `range()` without argumentsfix-range-without-args-crash
Close #3735
-rw-r--r-- | ChangeLog | 4 | ||||
-rw-r--r-- | pylint/checkers/refactoring/recommendation_checker.py | 2 | ||||
-rw-r--r-- | tests/functional/c/consider_using_enumerate.py | 5 |
3 files changed, 11 insertions, 0 deletions
@@ -91,6 +91,10 @@ Release date: TBA * Removed incorrect deprecation of ``inspect.getfullargspec`` +* Fix a crash in `consider-using-enumerate` when encountering `range()` without arguments + + Close #3735 + What's New in Pylint 2.6.0? =========================== diff --git a/pylint/checkers/refactoring/recommendation_checker.py b/pylint/checkers/refactoring/recommendation_checker.py index 0ca907f32..1617c934c 100644 --- a/pylint/checkers/refactoring/recommendation_checker.py +++ b/pylint/checkers/refactoring/recommendation_checker.py @@ -67,6 +67,8 @@ class RecommendationChecker(checkers.BaseChecker): return if not self._is_builtin(node.iter.func, "range"): return + if not node.iter.args: + return is_constant_zero = ( isinstance(node.iter.args[0], astroid.Const) and node.iter.args[0].value == 0 diff --git a/tests/functional/c/consider_using_enumerate.py b/tests/functional/c/consider_using_enumerate.py index cff00aeec..2ac382b18 100644 --- a/tests/functional/c/consider_using_enumerate.py +++ b/tests/functional/c/consider_using_enumerate.py @@ -66,3 +66,8 @@ class Good(object): # Should not suggest enumerate on self
for i in range(len(self)):
yield self[i]
+
+
+def does_not_crash_on_range_without_args():
+ for elem in range():
+ print(elem)
|