From 7e5f3c38bd1198b344c5cf6b963e5d4f9ae47720 Mon Sep 17 00:00:00 2001 From: James Morris <6653392+J-M0@users.noreply.github.com> Date: Fri, 11 Feb 2022 20:23:49 -0500 Subject: [PATCH] Add singledispatchmethod to singledispatch (#6089) --- stubs/singledispatch/@tests/stubtest_allowlist.txt | 1 + stubs/singledispatch/singledispatch.pyi | 14 +++++++++++++- 2 files changed, 14 insertions(+), 1 deletion(-) create mode 100644 stubs/singledispatch/@tests/stubtest_allowlist.txt diff --git a/stubs/singledispatch/@tests/stubtest_allowlist.txt b/stubs/singledispatch/@tests/stubtest_allowlist.txt new file mode 100644 index 000000000..d455fe6c1 --- /dev/null +++ b/stubs/singledispatch/@tests/stubtest_allowlist.txt @@ -0,0 +1 @@ +singledispatch.singledispatchmethod.__call__ # A lie to reflect that the descriptor get returns a callable diff --git a/stubs/singledispatch/singledispatch.pyi b/stubs/singledispatch/singledispatch.pyi index f264047ac..4a2af7296 100644 --- a/stubs/singledispatch/singledispatch.pyi +++ b/stubs/singledispatch/singledispatch.pyi @@ -1,4 +1,4 @@ -from typing import Any, Callable, Generic, Mapping, TypeVar, overload +from typing import Any, Callable, Generic, Mapping, Type, TypeVar, overload _T = TypeVar("_T") @@ -13,3 +13,15 @@ class _SingleDispatchCallable(Generic[_T]): def __call__(self, *args: Any, **kwargs: Any) -> _T: ... def singledispatch(func: Callable[..., _T]) -> _SingleDispatchCallable[_T]: ... + +class singledispatchmethod(Generic[_T]): + dispatcher: _SingleDispatchCallable[_T] + func: Callable[..., _T] + def __init__(self, func: Callable[..., _T]) -> None: ... + @overload + def register(self, cls: Type[Any], method: None = ...) -> Callable[[Callable[..., _T]], Callable[..., _T]]: ... + @overload + def register(self, cls: Callable[..., _T], method: None = ...) -> Callable[..., _T]: ... + @overload + def register(self, cls: Type[Any], method: Callable[..., _T]) -> Callable[..., _T]: ... + def __call__(self, *args: Any, **kwargs: Any) -> _T: ...