Skip to content

Commit 484e910

Browse files
committed
Fix crash when a slice object is called
1 parent f8f6ccd commit 484e910

File tree

4 files changed

+22
-2
lines changed

4 files changed

+22
-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: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -115,11 +115,17 @@ def visit_call(self, node: nodes.Call) -> None:
115115
called = safe_infer(node.func)
116116
if not called:
117117
return
118-
if called.qname() == "collections.namedtuple":
118+
if (
119+
isinstance(called, nodes.FunctionDef)
120+
and called.qname() == "collections.namedtuple"
121+
):
119122
self.add_message(
120123
"prefer-typing-namedtuple", node=node, confidence=INFERENCE
121124
)
122-
elif called.qname() == "builtins.float":
125+
elif (
126+
isinstance(called, nodes.ClassDef)
127+
and called.qname() == "builtins.float"
128+
):
123129
if (
124130
node.args
125131
and isinstance(node.args[0], nodes.Const)

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)