Add singledispatchmethod to singledispatch (#6089)

This commit is contained in:
James Morris
2022-02-11 20:23:49 -05:00
committed by GitHub
parent 418574f82c
commit 7e5f3c38bd
2 changed files with 14 additions and 1 deletions

View File

@@ -0,0 +1 @@
singledispatch.singledispatchmethod.__call__ # A lie to reflect that the descriptor get returns a callable

View File

@@ -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: ...