Closed
Description
test.py
:
def foo(h: bytes) -> int:
if h[5] == 2:
byteorder = "big"
elif h[5] == 1:
byteorder = "little"
else:
raise AssertionError(
f"unexpected ELF endianness: {h[5]}"
)
return int.from_bytes(h[16:18], byteorder=byteorder, signed=False)
Results in
$ mypy test.py
1.py:10:17: note: Revealed type is "builtins.str"
1.py:11:47: error: Argument "byteorder" to "from_bytes" of "int" has incompatible type "str"; expected "Union[Literal['little'], Literal['big']]"
With mypy-0.920 and later. 0.910 correctly inferred byteorder
as Literal['little'] | Literal['big']