From c4f3207437273226d710e3213d734b22c426d03a Mon Sep 17 00:00:00 2001 From: Shantanu <12621235+hauntsaninja@users.noreply.github.com> Date: Sun, 17 Jan 2021 17:01:17 -0800 Subject: [PATCH] functools: fix singledispatch (#4942) This is tricky, but should match the runtime logic better. Fixes #4408 --- stdlib/3/functools.pyi | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/stdlib/3/functools.pyi b/stdlib/3/functools.pyi index 562c32bcd..10c46f42e 100644 --- a/stdlib/3/functools.pyi +++ b/stdlib/3/functools.pyi @@ -88,10 +88,17 @@ class partialmethod(Generic[_T]): class _SingleDispatchCallable(Generic[_T]): registry: Mapping[Any, Callable[..., _T]] def dispatch(self, cls: Any) -> Callable[..., _T]: ... + # @fun.register(complex) + # def _(arg, verbose=False): ... @overload - def register(self, cls: Any) -> Callable[[Callable[..., _T]], Callable[..., _T]]: ... + def register(self, cls: type, func: None = ...) -> Callable[[Callable[..., _T]], Callable[..., _T]]: ... + # @fun.register + # def _(arg: int, verbose=False): @overload - def register(self, cls: Any, func: Callable[..., _T]) -> Callable[..., _T]: ... + def register(self, cls: Callable[..., _T], func: None = ...) -> Callable[..., _T]: ... + # fun.register(int, lambda x: x) + @overload + def register(self, cls: Type, func: Callable[..., _T]) -> Callable[..., _T]: ... def _clear_cache(self) -> None: ... def __call__(self, *args: Any, **kwargs: Any) -> _T: ... @@ -103,9 +110,11 @@ if sys.version_info >= (3, 8): func: Callable[..., _T] def __init__(self, func: Callable[..., _T]) -> None: ... @overload - def register(self, cls: Any, method: None = ...) -> Callable[[Callable[..., _T]], Callable[..., _T]]: ... + def register(self, cls: Type, method: None = ...) -> Callable[[Callable[..., _T]], Callable[..., _T]]: ... @overload - def register(self, cls: Any, method: Callable[..., _T]) -> Callable[..., _T]: ... + def register(self, cls: Callable[..., _T], method: None = ...) -> Callable[..., _T]: ... + @overload + def register(self, cls: Type, method: Callable[..., _T]) -> Callable[..., _T]: ... def __call__(self, *args: Any, **kwargs: Any) -> _T: ... class cached_property(Generic[_T]): func: Callable[[Any], _T]