Skip to content

Commit 714c99b

Browse files
authored
Fix singledispatch register signature (#13578)
1 parent 63e6ea8 commit 714c99b

File tree

1 file changed

+9
-4
lines changed

1 file changed

+9
-4
lines changed

stdlib/functools.pyi

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -151,20 +151,25 @@ class partialmethod(Generic[_T]):
151151
if sys.version_info >= (3, 9):
152152
def __class_getitem__(cls, item: Any, /) -> GenericAlias: ...
153153

154+
if sys.version_info >= (3, 11):
155+
_RegType: TypeAlias = type[Any] | types.UnionType
156+
else:
157+
_RegType: TypeAlias = type[Any]
158+
154159
class _SingleDispatchCallable(Generic[_T]):
155160
registry: types.MappingProxyType[Any, Callable[..., _T]]
156161
def dispatch(self, cls: Any) -> Callable[..., _T]: ...
157162
# @fun.register(complex)
158163
# def _(arg, verbose=False): ...
159164
@overload
160-
def register(self, cls: type[Any], func: None = None) -> Callable[[Callable[..., _T]], Callable[..., _T]]: ...
165+
def register(self, cls: _RegType, func: None = None) -> Callable[[Callable[..., _T]], Callable[..., _T]]: ...
161166
# @fun.register
162167
# def _(arg: int, verbose=False):
163168
@overload
164169
def register(self, cls: Callable[..., _T], func: None = None) -> Callable[..., _T]: ...
165170
# fun.register(int, lambda x: x)
166171
@overload
167-
def register(self, cls: type[Any], func: Callable[..., _T]) -> Callable[..., _T]: ...
172+
def register(self, cls: _RegType, func: Callable[..., _T]) -> Callable[..., _T]: ...
168173
def _clear_cache(self) -> None: ...
169174
def __call__(self, /, *args: Any, **kwargs: Any) -> _T: ...
170175

@@ -177,11 +182,11 @@ class singledispatchmethod(Generic[_T]):
177182
@property
178183
def __isabstractmethod__(self) -> bool: ...
179184
@overload
180-
def register(self, cls: type[Any], method: None = None) -> Callable[[Callable[..., _T]], Callable[..., _T]]: ...
185+
def register(self, cls: _RegType, method: None = None) -> Callable[[Callable[..., _T]], Callable[..., _T]]: ...
181186
@overload
182187
def register(self, cls: Callable[..., _T], method: None = None) -> Callable[..., _T]: ...
183188
@overload
184-
def register(self, cls: type[Any], method: Callable[..., _T]) -> Callable[..., _T]: ...
189+
def register(self, cls: _RegType, method: Callable[..., _T]) -> Callable[..., _T]: ...
185190
def __get__(self, obj: _S, cls: type[_S] | None = None) -> Callable[..., _T]: ...
186191

187192
class cached_property(Generic[_T_co]):

0 commit comments

Comments
 (0)