Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

@overload is required when using @dispatch #3853

Open
orenbenkiki opened this issue Aug 21, 2017 · 1 comment
Open

@overload is required when using @dispatch #3853

orenbenkiki opened this issue Aug 21, 2017 · 1 comment
Labels
bug mypy got something wrong false-positive mypy gave an error on correct code

Comments

@orenbenkiki
Copy link

Is there a way to type-check code that uses @dispatch?

For example, consider the following synthetic example code:

from multipledispatch import dispatch

@dispatch(int)
def foo(x: int) -> None:
    print('int')

@dispatch(str)
def foo(x: str) -> None:
    print('str')

foo(1)  # Prints 'int'.
foo('a')  # Prints 'str'.

When I try to type-check this code with mypy, I get error: 'overload' decorator expected, because mypy does not recognize the @dispatch decorator.

Adding @overload before each @dispatch would satisfy mypy. However, it raises a run time error saying You should not call an overloaded function.. This makes sense, as the semantics of @overload are "this is only a signature, the real body is elsewhere.".

It seems what is needed is for mypy to directly recognize @dispatch...?

@ilevkivskyi
Copy link
Member

This looks related to #2904

@ilevkivskyi ilevkivskyi added the bug mypy got something wrong label Aug 21, 2017
@ilevkivskyi ilevkivskyi added the false-positive mypy gave an error on correct code label May 20, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug mypy got something wrong false-positive mypy gave an error on correct code
Projects
None yet
Development

No branches or pull requests

2 participants