Type hint for a function that returns only a specific set of values
You can do that with literal types. from typing_extensions import Literal # from typing import Literal # Python 3.8 or higher def fun(b: int) -> Literal[“a”, “b”, “c”]: if b == 0: return “a” if b == 1: return “b” return “d” mypy is able to detect the return “d” as a invalid statement: error: … Read more