diff options
author | Jacob Walls <jacobtylerwalls@gmail.com> | 2022-05-01 09:53:54 -0400 |
---|---|---|
committer | Pierre Sassoulas <pierre.sassoulas@gmail.com> | 2022-05-02 16:38:19 +0200 |
commit | f6a0cfdbb682506b32fa0db7ffb08621fc711443 (patch) | |
tree | 13e729809534ed7620d4fcd532844e52e55df162 | |
parent | feca907976aea32abc9910c1b6800ff58dd65cc4 (diff) | |
download | pylint-git-f6a0cfdbb682506b32fa0db7ffb08621fc711443.tar.gz |
Fix false positive for ``unused-variable`` when specifying a metaclass via a call (#6481)
-rw-r--r-- | ChangeLog | 5 | ||||
-rw-r--r-- | doc/whatsnew/2.13.rst | 5 | ||||
-rw-r--r-- | pylint/checkers/variables.py | 4 | ||||
-rw-r--r-- | tests/functional/b/bugfix_local_scope_metaclass_1177.py | 10 |
4 files changed, 24 insertions, 0 deletions
@@ -29,6 +29,11 @@ Release date: TBA Closes #5930 +* Fix false positive for ``unused-variable`` for classes inside functions + and where a metaclass is provided via a call. + + Closes #4020 + What's New in Pylint 2.13.7? ============================ diff --git a/doc/whatsnew/2.13.rst b/doc/whatsnew/2.13.rst index c28b94023..ffac2c217 100644 --- a/doc/whatsnew/2.13.rst +++ b/doc/whatsnew/2.13.rst @@ -607,6 +607,11 @@ Other Changes Closes #5769 +* Fix false positive for ``unused-variable`` for classes inside functions + and where a metaclass is provided via a call. + + Closes #4020 + * Only raise ``not-callable`` when all the inferred values of a property are not callable. Closes #5931 diff --git a/pylint/checkers/variables.py b/pylint/checkers/variables.py index 65432d8ca..9b2b2bd7a 100644 --- a/pylint/checkers/variables.py +++ b/pylint/checkers/variables.py @@ -2813,6 +2813,10 @@ class VariablesChecker(BaseChecker): while not isinstance(attr, nodes.Name): attr = attr.expr name = attr.name + elif isinstance(klass._metaclass, nodes.Call) and isinstance( + klass._metaclass.func, nodes.Name + ): + name = klass._metaclass.func.name elif metaclass: name = metaclass.root().name diff --git a/tests/functional/b/bugfix_local_scope_metaclass_1177.py b/tests/functional/b/bugfix_local_scope_metaclass_1177.py index 22c07a330..06f36be52 100644 --- a/tests/functional/b/bugfix_local_scope_metaclass_1177.py +++ b/tests/functional/b/bugfix_local_scope_metaclass_1177.py @@ -20,6 +20,16 @@ def func_scope(): return Class2 +def func_scope_with_metaclass_from_call(): + def get_type(): + return type + + class Class2(metaclass=get_type()): + pass + + return Class2 + + class ClassScope: class Meta3(type): pass |