diff --git a/mypy/stubtest.py b/mypy/stubtest.py index b2506e6dcc022..7b5ce83de118d 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 a6733a9e8bd07..a52d9ef5de31a 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]: