From aaaae080aaf803b163ac31904697c3760cfef2d3 Mon Sep 17 00:00:00 2001 From: AlexWaygood Date: Wed, 23 Aug 2023 19:58:01 +0100 Subject: [PATCH] Stubtest: fix another enum-related edge case --- mypy/stubtest.py | 6 +++--- mypy/test/teststubtest.py | 20 ++++++++++++++++++++ 2 files changed, 23 insertions(+), 3 deletions(-) diff --git a/mypy/stubtest.py b/mypy/stubtest.py index b2506e6dcc02..7b5ce83de118 100644 --- a/mypy/stubtest.py +++ b/mypy/stubtest.py @@ -1551,10 +1551,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: diff --git a/mypy/test/teststubtest.py b/mypy/test/teststubtest.py index a6733a9e8bd0..a52d9ef5de31 100644 --- a/mypy/test/teststubtest.py +++ b/mypy/test/teststubtest.py @@ -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]: