You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Is there a way to type-check code that uses @dispatch?
For example, consider the following synthetic example code:
frommultipledispatchimportdispatch@dispatch(int)deffoo(x: int) ->None:
print('int')
@dispatch(str)deffoo(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...?
The text was updated successfully, but these errors were encountered:
Is there a way to type-check code that uses
@dispatch
?For example, consider the following synthetic example code:
When I try to type-check this code with
mypy
, I geterror: 'overload' decorator expected
, becausemypy
does not recognize the@dispatch
decorator.Adding
@overload
before each@dispatch
would satisfymypy
. However, it raises a run time error sayingYou 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
...?The text was updated successfully, but these errors were encountered: