Skip to content

Commit 59af51b

Browse files
committed
Fix a crash in consider-using-enumerate when encountering range() without arguments
Close #3735
1 parent d168c23 commit 59af51b

File tree

3 files changed

+11
-0
lines changed

3 files changed

+11
-0
lines changed

ChangeLog

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,10 @@ Release date: TBA
9595

9696
* Removed incorrect deprecation of ``inspect.getfullargspec``
9797

98+
* Fix a crash in `consider-using-enumerate` when encountering `range()` without arguments
99+
100+
Close #3735
101+
98102
What's New in Pylint 2.6.0?
99103
===========================
100104

pylint/checkers/refactoring/recommendation_checker.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,8 @@ def visit_for(self, node):
6767
return
6868
if not self._is_builtin(node.iter.func, "range"):
6969
return
70+
if not node.iter.args:
71+
return
7072
is_constant_zero = (
7173
isinstance(node.iter.args[0], astroid.Const)
7274
and node.iter.args[0].value == 0

tests/functional/c/consider_using_enumerate.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,3 +66,8 @@ def __iter__(self):
6666
# Should not suggest enumerate on self
6767
for i in range(len(self)):
6868
yield self[i]
69+
70+
71+
def does_not_crash_on_range_without_args():
72+
for elem in range():
73+
print(elem)

0 commit comments

Comments
 (0)