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
I believe this is different from other issues about singledispatch (#2904).
This is the program that does not type-check:
from singledispatch import singledispatch
class A:
pass
class B(A):
pass
@singledispatch
def base(x, **kw):
pass
@base.register(A)
@singledispatch
def a(x):
print('a')
@a.register(B)
def b(x):
print('b')
base(A())
# want "base" and "a" both dispatch to "b"
base(B())
a(B())
Expected output from running it:
a
b
b
running mypy 0.501 with Python 3.5 gives the following errors:
t.py:13: error: Argument 1 has incompatible type _SingleDispatchCallable[Any]; expected Callable[..., Any]
t.py:18: error: Callable[..., Any] has no attribute "register"
Next is just the motivation part - why do we need this :)
Why such a complicated program: I want both "base" and "a" dispatch to "b", because "base" is a more generic function that works for any type supported by our library, and "a" is less generic, and all functions that dispatch from "a" share a common signature. So the user can import "a" and get more help from the IDE (and mypy) about supported arguments:
I believe this is different from other issues about singledispatch (#2904).
This is the program that does not type-check:
Expected output from running it:
running mypy 0.501 with Python 3.5 gives the following errors:
Next is just the motivation part - why do we need this :)
Why such a complicated program: I want both "base" and "a" dispatch to "b", because "base" is a more generic function that works for any type supported by our library, and "a" is less generic, and all functions that dispatch from "a" share a common signature. So the user can import "a" and get more help from the IDE (and mypy) about supported arguments:
Real code that fails to typecheck is here: https://github.com/TeamHG-Memex/eli5/blob/724c63a9b97e44eef8264305e66e808d249810c4/eli5/sklearn/explain_weights.py#L114
The text was updated successfully, but these errors were encountered: