Open
Description
[This was originally in a comment by @Dreamsorcerer]
...
This issue has mostly talked about the redefinition error. But, we should also have singledispatch typing working. e.g. With this example:
@singledispatch
def foo(data: object) -> NoReturn:
raise ValueError(f"Unhandled type {type(data)}")
@foo.register
def _(data: str) -> str:
return data
@foo.register
def _(data: int) -> str:
return str(data)
a = foo(7)
reveal_type(a)
You also get errors due to not recognising the overloads:
src/service/transaction_status_service.py:72: error: Need type annotation for "a" [var-annotated]
src/service/transaction_status_service.py:73: note: Revealed type is "<nothing>"
It would be good for mypy to treat the @foo.register
like an @overload
.
I was also getting unreachable code errors after every call to the defined function. However, I was unable to reproduce it with a minimal example, so not sure exactly what is causing that.