Код: Выделить всё
from typing import Literal
def expects_literal(x: Literal["foo", "bar"]) -> None:
print(f"{x=}")
def fails_mypy_check(y: str) -> None:
if y in ["foo", "bar"]:
expects_literal(y)
else:
print("format incorrect")
< /code>
Результаты: < /p>
mwe.py:8: error: Argument 1 to "expects_literal" has incompatible type "str"; expected "Literal['foo', 'bar']" [arg-type]
Подробнее здесь: https://stackoverflow.com/questions/797 ... arrow-valu