Skip to content

The aim of this repo is to allow alternative syntaxes for code, that otherwise would be typed with `@typing.overload`.

Notifications You must be signed in to change notification settings

SoloJacobs/overload_syntactic_sugar

Folders and files

NameName
Last commit message
Last commit date

Latest commit

5652dba · Aug 7, 2022

History

12 Commits
Aug 7, 2022
Aug 7, 2022
Aug 7, 2022

Repository files navigation

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

About

The aim of this repo is to allow alternative syntaxes for code, that otherwise would be typed with `@typing.overload`.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages