Skip to content

Commit

Permalink
stubtest: fix edge case for bytes enum subclasses (#15943)
Browse files Browse the repository at this point in the history
  • Loading branch information
AlexWaygood authored Aug 24, 2023
1 parent 0b303b5 commit 4077dc6
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 3 deletions.
6 changes: 3 additions & 3 deletions mypy/stubtest.py
Original file line number Diff line number Diff line change
Expand Up @@ -1552,10 +1552,10 @@ def anytype() -> mypy.types.AnyType:
fallback = mypy.types.Instance(type_info, [anytype() for _ in type_info.type_vars])

value: bool | int | str
if isinstance(runtime, bytes):
value = bytes_to_human_readable_repr(runtime)
elif isinstance(runtime, enum.Enum) and isinstance(runtime.name, str):
if isinstance(runtime, enum.Enum) and isinstance(runtime.name, str):
value = runtime.name
elif isinstance(runtime, bytes):
value = bytes_to_human_readable_repr(runtime)
elif isinstance(runtime, (bool, int, str)):
value = runtime
else:
Expand Down
20 changes: 20 additions & 0 deletions mypy/test/teststubtest.py
Original file line number Diff line number Diff line change
Expand Up @@ -1068,6 +1068,26 @@ def spam(x=Flags4(0)): pass
""",
error="spam",
)
yield Case(
stub="""
from typing_extensions import Final, Literal
class BytesEnum(bytes, enum.Enum):
a: bytes
FOO: Literal[BytesEnum.a]
BAR: Final = BytesEnum.a
BAZ: BytesEnum
EGGS: bytes
""",
runtime="""
class BytesEnum(bytes, enum.Enum):
a = b'foo'
FOO = BytesEnum.a
BAR = BytesEnum.a
BAZ = BytesEnum.a
EGGS = BytesEnum.a
""",
error=None,
)

@collect_cases
def test_decorator(self) -> Iterator[Case]:
Expand Down

0 comments on commit 4077dc6

Please sign in to comment.