Skip to content

Commit

Permalink
Fix false positive for unused-variable when specifying a metaclas…
Browse files Browse the repository at this point in the history
…s via a call (#6481)
  • Loading branch information
jacobtylerwalls authored and Pierre-Sassoulas committed May 2, 2022
1 parent b55ac6c commit ce4b9bd
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 0 deletions.
5 changes: 5 additions & 0 deletions ChangeLog
Original file line number Diff line number Diff line change
Expand Up @@ -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?
============================
Expand Down
5 changes: 5 additions & 0 deletions doc/whatsnew/2.13.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 4 additions & 0 deletions pylint/checkers/variables.py
Original file line number Diff line number Diff line change
Expand Up @@ -2813,6 +2813,10 @@ def _check_classdef_metaclasses(self, klass, parent_node):
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

Expand Down
10 changes: 10 additions & 0 deletions tests/functional/b/bugfix_local_scope_metaclass_1177.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,16 @@ class Class2(metaclass=Meta2):
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
Expand Down

0 comments on commit ce4b9bd

Please sign in to comment.