From 547433bb1579387968b7aea9dd890fb91ec6f888 Mon Sep 17 00:00:00 2001 From: Alex Waygood Date: Sun, 9 Jun 2024 09:35:15 +0100 Subject: [PATCH] Reduce false positives from Y052 (#492) --- CHANGELOG.md | 1 + pyi.py | 10 +--------- tests/attribute_annotations.pyi | 5 +++++ 3 files changed, 7 insertions(+), 9 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index f3edc445..8fde2a26 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,6 +6,7 @@ Bugfixes * Allow the use of `typing_extensions.TypeVar` in stubs. `typing_extensions.TypeVar` has the *default* parameter, which only exists on Python 3.13+ when using `typing.TypeVar`. +* Reduce false positives from Y052 in relation to enum subclasses. ## 24.4.1 diff --git a/pyi.py b/pyi.py index dba653e3..88c7b8a8 100644 --- a/pyi.py +++ b/pyi.py @@ -701,11 +701,6 @@ def _analyse_typing_Literal(node: ast.Subscript) -> TypingLiteralAnalysis: ) -_KNOWN_ENUM_BASES = frozenset( - {"Enum", "Flag", "IntEnum", "IntFlag", "StrEnum", "ReprEnum"} -) - - _COMMON_METACLASSES = { "type": "builtins", "ABCMeta": "abc", @@ -739,10 +734,7 @@ def is_typeddict_class(self) -> bool: @cached_property def is_enum_class(self) -> bool: - return any( - self.contains_in_bases(enum_cls, from_={"enum"}) - for enum_cls in _KNOWN_ENUM_BASES - ) + return any(base_name.endswith(("Enum", "Flag")) for base_name in self.bases_map) @cached_property def is_metaclass(self) -> bool: diff --git a/tests/attribute_annotations.pyi b/tests/attribute_annotations.pyi index 18abc86b..2014daf8 100644 --- a/tests/attribute_annotations.pyi +++ b/tests/attribute_annotations.pyi @@ -146,3 +146,8 @@ class Enum6(ReprEnum): class Enum7(enum.Enum): FOO = "foo" + +class SpecialEnum(enum.Enum): ... + +class SubclassOfSpecialEnum(SpecialEnum): + STILL_OKAY = "foo"