Hacker News new | ask | show | jobs
by uranusjr 1737 days ago
Another solution if you write fully-typed Python is to use typing.Literal:

    calc(x, y, mode="gain")
where the function is defined as

    def calc(
        x: float,
        y: float,
        *,
        mode: Literal["gain", "render"],
    ) -> float:
        ...
This is IMO one of the best things type annotations provide. Combined with Protocol you can write much better structured code with little or no runtime costs.