Skip to content

Latest commit

 

History

History
27 lines (20 loc) · 577 Bytes

README.md

File metadata and controls

27 lines (20 loc) · 577 Bytes

Sometimes I write code like this:

import typing


class A(typing.Protocol):
    @typing.overload
    def get(self, key: typing.Literal["a"]) -> int:
        ...

    @typing.overload
    def get(self, key: typing.Literal["b"]) -> str:
        ...

    @typing.overload
    def get(self, key: typing.Literal["a", "b"]) -> int | str:
        ...

However, I would much rather implement a special Get class, which allows me use syntax very similiar to TypedDict:

class A(Get):  # Should do the same as the definition above.
    a: int
    b: str