Python type hints: How to use Literal with strings to conform with mypy?
Python type hints: How to use Literal with strings to conform with mypy? Question: I want to restrict the possible input arguments by using typing.Literal. The following code works just fine, however, mypy is complaining. from typing import Literal def literal_func(string_input: Literal["best", "worst"]) -> int: if string_input == "best": return 1 elif string_input == "worst": …