Skip to content
Merged
3 changes: 3 additions & 0 deletions doc/whatsnew/fragments/10334.bugfix
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
Using a slice as a class decorator now raise a 'not-callable' message instead of crashing pylint. A lot of checks that dealt with decorators (too many to list) are now shortcut if the decorator can't immediately be inferred to a function or class definition.

Closes #10334
2 changes: 1 addition & 1 deletion pylint/checkers/deprecated.py
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ def visit_decorators(self, node: nodes.Decorators) -> None:
inferred = safe_infer(children[0].func)
else:
inferred = safe_infer(children[0])
if not inferred:
if not isinstance(inferred, (nodes.ClassDef, nodes.FunctionDef)):
return
qname = inferred.qname()
if qname in self.deprecated_decorators():
Expand Down
2 changes: 1 addition & 1 deletion pylint/checkers/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -875,7 +875,7 @@ def decorated_with(
if any(
i.name in qnames or i.qname() in qnames
for i in decorator_node.infer()
if i is not None and not isinstance(i, util.UninferableBase)
if isinstance(i, (nodes.ClassDef, nodes.FunctionDef))
):
return True
except astroid.InferenceError:
Expand Down
6 changes: 6 additions & 0 deletions tests/functional/r/regression_02/regression_10334.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
"""Test for slice object used as a decorator."""
# pylint: disable=too-few-public-methods
s = slice(-2)
@s() # [not-callable]
class A:
"""Class with a slice decorator."""
1 change: 1 addition & 0 deletions tests/functional/r/regression_02/regression_10334.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
not-callable:4:1:4:4:A:s is not callable:UNDEFINED
Loading