summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorClaudiu Popa <pcmanticore@gmail.com>2019-09-23 09:17:19 +0200
committerClaudiu Popa <pcmanticore@gmail.com>2019-09-23 09:17:23 +0200
commitd39f7abc50bebd46bec51d4776b622b5176d3420 (patch)
tree38b0ab7c2f259d19f7dbd83743d710e5f4da7921
parentde75ba13eedd6cb6e84a96e0b79765e890c46efe (diff)
downloadpylint-git-d39f7abc50bebd46bec51d4776b622b5176d3420.tar.gz
Allow signature mutators to be verified against the name as well as qualified name of the decorators
This is to simplify its use in single files, since `qname()` expects the decorator name to be fully qualified (but might be a hindrance for single file analysis)
-rw-r--r--pylint/checkers/utils.py6
-rw-r--r--tests/functional/a/arguments.py18
-rw-r--r--tests/functional/a/arguments.rc2
3 files changed, 24 insertions, 2 deletions
diff --git a/pylint/checkers/utils.py b/pylint/checkers/utils.py
index 153bc40ff..def655769 100644
--- a/pylint/checkers/utils.py
+++ b/pylint/checkers/utils.py
@@ -755,9 +755,13 @@ def decorated_with(func: astroid.FunctionDef, qnames: Iterable[str]) -> bool:
"""Determine if the `func` node has a decorator with the qualified name `qname`."""
decorators = func.decorators.nodes if func.decorators else []
for decorator_node in decorators:
+ if isinstance(decorator_node, astroid.Call):
+ # We only want to infer the function name
+ decorator_node = decorator_node.func
try:
if any(
- i is not None and i.qname() in qnames for i in decorator_node.infer()
+ i is not None and i.qname() in qnames or i.name in qnames
+ for i in decorator_node.infer()
):
return True
except astroid.InferenceError:
diff --git a/tests/functional/a/arguments.py b/tests/functional/a/arguments.py
index 816208d29..7d0c74f83 100644
--- a/tests/functional/a/arguments.py
+++ b/tests/functional/a/arguments.py
@@ -228,14 +228,32 @@ def mutation_decorator(fun):
return wrapper
+def other_mutation_decorator(fun):
+ """Another decorator that changes a function's signature"""
+ def wrapper(*args, do_something=True, **kwargs):
+ if do_something:
+ return fun(*args, **kwargs)
+
+ return None
+
+ return wrapper
+
+
@mutation_decorator
def mutated_function(arg):
return arg
+@other_mutation_decorator
+def mutated(arg):
+ return arg
+
+
mutated_function(do_something=False)
mutated_function()
+mutated(do_something=True)
+
def func(one, two, three):
return one + two + three
diff --git a/tests/functional/a/arguments.rc b/tests/functional/a/arguments.rc
index 2b7745370..4764d05da 100644
--- a/tests/functional/a/arguments.rc
+++ b/tests/functional/a/arguments.rc
@@ -1,2 +1,2 @@
[TYPECHECK]
-signature-mutators=functional.a.arguments.mutation_decorator
+signature-mutators=functional.a.arguments.mutation_decorator,other_mutation_decorator