Skip to content

Commit

Permalink
Reduce false positives from Y052 (#492)
Browse files Browse the repository at this point in the history
  • Loading branch information
AlexWaygood committed Jun 9, 2024
1 parent 87b2085 commit 547433b
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 9 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
10 changes: 1 addition & 9 deletions pyi.py
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down Expand Up @@ -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:
Expand Down
5 changes: 5 additions & 0 deletions tests/attribute_annotations.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -146,3 +146,8 @@ class Enum6(ReprEnum):

class Enum7(enum.Enum):
FOO = "foo"

class SpecialEnum(enum.Enum): ...

class SubclassOfSpecialEnum(SpecialEnum):
STILL_OKAY = "foo"

0 comments on commit 547433b

Please sign in to comment.