Skip to content

Commit

Permalink
more
Browse files Browse the repository at this point in the history
  • Loading branch information
hauntsaninja committed Oct 29, 2024
1 parent 66d4ca2 commit 96206da
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 5 deletions.
2 changes: 1 addition & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ class Pet(Enum):
DOG: int

# Mypy will now issue a warning if it detects this situation in type stubs:
# Detected an enum in a type stub with zero members.
# Detected enum "Pet" in a type stub with zero members.
# There is a chance this is due to a recent change in the semantics of enum membership.
# If so, use `member = value` to mark an enum member, instead of `member: type

Expand Down
4 changes: 2 additions & 2 deletions mypy/checker.py
Original file line number Diff line number Diff line change
Expand Up @@ -2598,10 +2598,10 @@ def check_enum(self, defn: ClassDef) -> None:
if base.is_enum and base.fullname not in ENUM_BASES:
self.check_final_enum(defn, base)

if self.is_stub and not self.is_typeshed_stub and self.tree.fullname != "enum":
if self.is_stub and self.tree.fullname not in {"enum", "_typeshed"}:
if not defn.info.enum_members:
self.fail(
"Detected an enum in a type stub with zero members. "
f'Detected enum "{defn.info.fullname}" in a type stub with zero members. '
"There is a chance this is due to a recent change in the semantics of "
"enum membership. If so, use `member = value` to mark an enum member, "
"instead of `member: type`",
Expand Down
4 changes: 2 additions & 2 deletions test-data/unit/check-enum.test
Original file line number Diff line number Diff line change
Expand Up @@ -1788,7 +1788,7 @@ import lib

[file lib.pyi]
from enum import Enum
class A(Enum): # E: Detected an enum in a type stub with zero members. There is a chance this is due to a recent change in the semantics of enum membership. If so, use `member = value` to mark an enum member, instead of `member: type` \
class A(Enum): # E: Detected enum "lib.A" in a type stub with zero members. There is a chance this is due to a recent change in the semantics of enum membership. If so, use `member = value` to mark an enum member, instead of `member: type` \
# N: See https://typing.readthedocs.io/en/latest/spec/enums.html#defining-members
x: int
class B(A): # E: Cannot extend enum with existing members: "A"
Expand All @@ -1797,7 +1797,7 @@ class B(A): # E: Cannot extend enum with existing members: "A"
class C(Enum):
x = 1
class D(C): # E: Cannot extend enum with existing members: "C" \
# E: Detected an enum in a type stub with zero members. There is a chance this is due to a recent change in the semantics of enum membership. If so, use `member = value` to mark an enum member, instead of `member: type` \
# E: Detected enum "lib.D" in a type stub with zero members. There is a chance this is due to a recent change in the semantics of enum membership. If so, use `member = value` to mark an enum member, instead of `member: type` \
# N: See https://typing.readthedocs.io/en/latest/spec/enums.html#defining-members
x: int # E: Cannot assign to final name "x"
[builtins fixtures/bool.pyi]
Expand Down

0 comments on commit 96206da

Please sign in to comment.