Skip to content

Commit 5f7529f

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

File tree

4 files changed

+21
-2
lines changed

4 files changed

+21
-2
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: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,10 @@
1010
from astroid import nodes
1111

1212
from pylint.checkers import BaseChecker, utils
13-
from pylint.checkers.utils import only_required_for_messages, safe_infer
13+
from pylint.checkers.utils import (
14+
only_required_for_messages,
15+
safe_infer,
16+
)
1417
from pylint.interfaces import INFERENCE
1518

1619
if TYPE_CHECKING:
@@ -113,7 +116,9 @@ def open(self) -> None:
113116
def visit_call(self, node: nodes.Call) -> None:
114117
if self._py36_plus:
115118
called = safe_infer(node.func)
116-
if not called:
119+
if not called or not isinstance(
120+
called, (nodes.FunctionDef, nodes.ClassDef)
121+
):
117122
return
118123
if called.qname() == "collections.namedtuple":
119124
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)