Skip to content

Commit

Permalink
B902: Add exceptions for standard library metaclasses (#415)
Browse files Browse the repository at this point in the history
I faced a false positive when deriving my metaclass from ABCMeta, which should be fixed with this commit. I also added EnumMeta to this list, because it was the only other public metaclass in the standard library.
  • Loading branch information
henzef committed Nov 26, 2023
1 parent 393fea1 commit cfc2429
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 2 deletions.
2 changes: 1 addition & 1 deletion bugbear.py
Original file line number Diff line number Diff line change
Expand Up @@ -1046,7 +1046,7 @@ def is_classmethod(decorators: Set[str]) -> bool:
return

bases = {b.id for b in cls.bases if isinstance(b, ast.Name)}
if "type" in bases:
if any(basetype in bases for basetype in ("type", "ABCMeta", "EnumMeta")):
if is_classmethod(decorators):
expected_first_args = B902.metacls
kind = "metaclass class"
Expand Down
2 changes: 1 addition & 1 deletion tests/b024.py
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ def method(self):


class non_keyword_abcmeta_1(ABCMeta): # safe
def method(self):
def method(cls):
foo()


Expand Down

0 comments on commit cfc2429

Please sign in to comment.