Skip to content

Commit b054f06

Browse files
committed
[functools] Use ParamSpec for single dispatch
1 parent c08fa66 commit b054f06

File tree

1 file changed

+17
-16
lines changed

1 file changed

+17
-16
lines changed

stdlib/functools.pyi

Lines changed: 17 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ __all__ = [
2626
_T = TypeVar("_T")
2727
_T_co = TypeVar("_T_co", covariant=True)
2828
_S = TypeVar("_S")
29+
_P = ParamSpec("_P")
2930
_PWrapped = ParamSpec("_PWrapped")
3031
_RWrapped = TypeVar("_RWrapped")
3132
_PWrapper = ParamSpec("_PWrapper")
@@ -195,38 +196,38 @@ else:
195196
_RegType: TypeAlias = type[Any]
196197

197198
@type_check_only
198-
class _SingleDispatchCallable(Generic[_T]):
199-
registry: types.MappingProxyType[Any, Callable[..., _T]]
200-
def dispatch(self, cls: Any) -> Callable[..., _T]: ...
199+
class _SingleDispatchCallable(Generic[_P, _T]):
200+
registry: types.MappingProxyType[Any, Callable[_P, _T]]
201+
def dispatch(self, cls: Any) -> Callable[_P, _T]: ...
201202
# @fun.register(complex)
202203
# def _(arg, verbose=False): ...
203204
@overload
204-
def register(self, cls: _RegType, func: None = None) -> Callable[[Callable[..., _T]], Callable[..., _T]]: ...
205+
def register(self, cls: _RegType, func: None = None) -> Callable[[Callable[_P, _T]], Callable[_P, _T]]: ...
205206
# @fun.register
206207
# def _(arg: int, verbose=False):
207208
@overload
208-
def register(self, cls: Callable[..., _T], func: None = None) -> Callable[..., _T]: ...
209+
def register(self, cls: Callable[_P, _T], func: None = None) -> Callable[_P, _T]: ...
209210
# fun.register(int, lambda x: x)
210211
@overload
211-
def register(self, cls: _RegType, func: Callable[..., _T]) -> Callable[..., _T]: ...
212+
def register(self, cls: _RegType, func: Callable[_P, _T]) -> Callable[_P, _T]: ...
212213
def _clear_cache(self) -> None: ...
213-
def __call__(self, /, *args: Any, **kwargs: Any) -> _T: ...
214+
def __call__(self, /, *args: _P.args, **kwargs: _P.kwargs) -> _T: ...
214215

215-
def singledispatch(func: Callable[..., _T]) -> _SingleDispatchCallable[_T]: ...
216+
def singledispatch(func: Callable[_P, _T]) -> _SingleDispatchCallable[_P, _T]: ...
216217

217-
class singledispatchmethod(Generic[_T]):
218-
dispatcher: _SingleDispatchCallable[_T]
219-
func: Callable[..., _T]
220-
def __init__(self, func: Callable[..., _T]) -> None: ...
218+
class singledispatchmethod(Generic[_P, _T]):
219+
dispatcher: _SingleDispatchCallable[_P, _T]
220+
func: Callable[_P, _T]
221+
def __init__(self, func: Callable[_P, _T]) -> None: ...
221222
@property
222223
def __isabstractmethod__(self) -> bool: ...
223224
@overload
224-
def register(self, cls: _RegType, method: None = None) -> Callable[[Callable[..., _T]], Callable[..., _T]]: ...
225+
def register(self, cls: _RegType, method: None = None) -> Callable[[Callable[_P, _T]], Callable[_P, _T]]: ...
225226
@overload
226-
def register(self, cls: Callable[..., _T], method: None = None) -> Callable[..., _T]: ...
227+
def register(self, cls: Callable[_P, _T], method: None = None) -> Callable[_P, _T]: ...
227228
@overload
228-
def register(self, cls: _RegType, method: Callable[..., _T]) -> Callable[..., _T]: ...
229-
def __get__(self, obj: _S, cls: type[_S] | None = None) -> Callable[..., _T]: ...
229+
def register(self, cls: _RegType, method: Callable[_P, _T]) -> Callable[_P, _T]: ...
230+
def __get__(self, obj: _S, cls: type[_S] | None = None) -> Callable[_P, _T]: ...
230231

231232
class cached_property(Generic[_T_co]):
232233
func: Callable[[Any], _T_co]

0 commit comments

Comments
 (0)