Skip to content

Commit be9701c

Browse files
committed
Fix crash when a slice object is called
1 parent 133681e commit be9701c

File tree

4 files changed

+15
-1
lines changed

4 files changed

+15
-1
lines changed
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
Fix crash for ``prefer-typing-namedtuple`` and ``consider-math-not-float`` when
2+
a ``slice`` object is called.
3+
4+
Closes #10708

pylint/extensions/code_style.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,7 @@ def open(self) -> None:
113113
def visit_call(self, node: nodes.Call) -> None:
114114
if self._py36_plus:
115115
called = safe_infer(node.func)
116-
if not called:
116+
if not (called and isinstance(called, (nodes.FunctionDef, nodes.ClassDef))):
117117
return
118118
if called.qname() == "collections.namedtuple":
119119
self.add_message(

tests/functional/ext/code_style/cs_prefer_typing_namedtuple.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,3 +7,8 @@ class SearchMatch(
77
namedtuple('SearchMatch', ['els', 'index', 'iterator']) # [prefer-typing-namedtuple]
88
):
99
"""Adapted from primer package `music21`."""
10+
11+
12+
# Regression test for https://github.com/pylint-dev/pylint/issues/10708
13+
x = slice(42)
14+
x() # pylint: disable=not-callable

tests/functional/ext/code_style/cs_use_math_not_float.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,3 +16,8 @@
1616
upper_nan_float = float("NaN") # [consider-math-not-float]
1717
typo_nan_float = float("nani") # [consider-math-not-float]
1818
other_typo_nan_float = float("nna") # [consider-math-not-float]
19+
20+
21+
# Regression test for https://github.com/pylint-dev/pylint/issues/10708
22+
x = slice(42)
23+
x() # pylint: disable=not-callable

0 commit comments

Comments
 (0)