Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Reduce false positives from Y052 #492

Merged
merged 11 commits into from
Jun 9, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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"
Loading