Following #7188, we can now have:
fromtypingimportoverloadfromtyping_extensionsimportLiteralclassCat:
@overloaddef__new__(cls, name: Literal['Tabby']) ->'Tabby': ...
@overloaddef__new__(cls, name: Literal['Kitty']) ->'Kitty': ...
def__new__(cls, name: str) ->'Cat': ...
classKitty(Cat):
passclassTabby(Cat):
passreveal_type(Cat('Kitty'))
reveal_type(Cat('Tabby'))result in:
Revealed type is 'test.Kitty'
Revealed type is 'test.Tabby'
(Meant as a trivial example.)
However, this doesn't extend to derived classes:
reveal_type(Tabby('Kitty'))
reveal_type(Tabby('Tabby'))would result in:
Revealed type is 'test.Tabby'
Revealed type is 'test.Tabby'
I'm using mypy 0.761.
Following #7188, we can now have:
result in:
(Meant as a trivial example.)
However, this doesn't extend to derived classes:
would result in:
I'm using mypy 0.761.