From e5dc2883468420a7bfe358f9ff26184191fc4b00 Mon Sep 17 00:00:00 2001 From: "Philipp A." Date: Tue, 4 Mar 2025 12:40:52 +0100 Subject: [PATCH 1/4] fix singledispatch register signature --- stdlib/functools.pyi | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/stdlib/functools.pyi b/stdlib/functools.pyi index 10563e654b37..770ef48b1b7f 100644 --- a/stdlib/functools.pyi +++ b/stdlib/functools.pyi @@ -157,14 +157,16 @@ class _SingleDispatchCallable(Generic[_T]): # @fun.register(complex) # def _(arg, verbose=False): ... @overload - def register(self, cls: type[Any], func: None = None) -> Callable[[Callable[..., _T]], Callable[..., _T]]: ... + def register( + self, cls: type[Any] | types.UnionType, func: None = None + ) -> Callable[[Callable[..., _T]], Callable[..., _T]]: ... # @fun.register # def _(arg: int, verbose=False): @overload def register(self, cls: Callable[..., _T], func: None = None) -> Callable[..., _T]: ... # fun.register(int, lambda x: x) @overload - def register(self, cls: type[Any], func: Callable[..., _T]) -> Callable[..., _T]: ... + def register(self, cls: type[Any] | types.UnionType, func: Callable[..., _T]) -> Callable[..., _T]: ... def _clear_cache(self) -> None: ... def __call__(self, /, *args: Any, **kwargs: Any) -> _T: ... @@ -177,11 +179,13 @@ class singledispatchmethod(Generic[_T]): @property def __isabstractmethod__(self) -> bool: ... @overload - def register(self, cls: type[Any], method: None = None) -> Callable[[Callable[..., _T]], Callable[..., _T]]: ... + def register( + self, cls: type[Any] | types.UnionType, method: None = None + ) -> Callable[[Callable[..., _T]], Callable[..., _T]]: ... @overload def register(self, cls: Callable[..., _T], method: None = None) -> Callable[..., _T]: ... @overload - def register(self, cls: type[Any], method: Callable[..., _T]) -> Callable[..., _T]: ... + def register(self, cls: type[Any] | types.UnionType, method: Callable[..., _T]) -> Callable[..., _T]: ... def __get__(self, obj: _S, cls: type[_S] | None = None) -> Callable[..., _T]: ... class cached_property(Generic[_T_co]): From 4170e002364783a55c2ac7b40be246cdb11522a8 Mon Sep 17 00:00:00 2001 From: "Philipp A." Date: Tue, 4 Mar 2025 12:44:50 +0100 Subject: [PATCH 2/4] 3.9 support --- stdlib/functools.pyi | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/stdlib/functools.pyi b/stdlib/functools.pyi index 770ef48b1b7f..861c15ad5e5a 100644 --- a/stdlib/functools.pyi +++ b/stdlib/functools.pyi @@ -151,22 +151,25 @@ class partialmethod(Generic[_T]): if sys.version_info >= (3, 9): def __class_getitem__(cls, item: Any, /) -> GenericAlias: ... +if sys.version_info >= (3, 10): + _RegType = type[Any] | types.UnionType +else: + _RegType = type[Any] + class _SingleDispatchCallable(Generic[_T]): registry: types.MappingProxyType[Any, Callable[..., _T]] def dispatch(self, cls: Any) -> Callable[..., _T]: ... # @fun.register(complex) # def _(arg, verbose=False): ... @overload - def register( - self, cls: type[Any] | types.UnionType, func: None = None - ) -> Callable[[Callable[..., _T]], Callable[..., _T]]: ... + def register(self, cls: _RegType, func: None = None) -> Callable[[Callable[..., _T]], Callable[..., _T]]: ... # @fun.register # def _(arg: int, verbose=False): @overload def register(self, cls: Callable[..., _T], func: None = None) -> Callable[..., _T]: ... # fun.register(int, lambda x: x) @overload - def register(self, cls: type[Any] | types.UnionType, func: Callable[..., _T]) -> Callable[..., _T]: ... + def register(self, cls: _RegType, func: Callable[..., _T]) -> Callable[..., _T]: ... def _clear_cache(self) -> None: ... def __call__(self, /, *args: Any, **kwargs: Any) -> _T: ... @@ -179,13 +182,11 @@ class singledispatchmethod(Generic[_T]): @property def __isabstractmethod__(self) -> bool: ... @overload - def register( - self, cls: type[Any] | types.UnionType, method: None = None - ) -> Callable[[Callable[..., _T]], Callable[..., _T]]: ... + def register(self, cls: _RegType, method: None = None) -> Callable[[Callable[..., _T]], Callable[..., _T]]: ... @overload def register(self, cls: Callable[..., _T], method: None = None) -> Callable[..., _T]: ... @overload - def register(self, cls: type[Any] | types.UnionType, method: Callable[..., _T]) -> Callable[..., _T]: ... + def register(self, cls: _RegType, method: Callable[..., _T]) -> Callable[..., _T]: ... def __get__(self, obj: _S, cls: type[_S] | None = None) -> Callable[..., _T]: ... class cached_property(Generic[_T_co]): From 1151d0fe382359b8c430b10f3f2a2d2e666155f9 Mon Sep 17 00:00:00 2001 From: "Philipp A." Date: Tue, 4 Mar 2025 12:45:34 +0100 Subject: [PATCH 3/4] use correct Python version --- stdlib/functools.pyi | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/stdlib/functools.pyi b/stdlib/functools.pyi index 861c15ad5e5a..66ed626ef853 100644 --- a/stdlib/functools.pyi +++ b/stdlib/functools.pyi @@ -151,7 +151,7 @@ class partialmethod(Generic[_T]): if sys.version_info >= (3, 9): def __class_getitem__(cls, item: Any, /) -> GenericAlias: ... -if sys.version_info >= (3, 10): +if sys.version_info >= (3, 11): _RegType = type[Any] | types.UnionType else: _RegType = type[Any] From aae247bf5b09814c5c96e78fcca2d72898756ae3 Mon Sep 17 00:00:00 2001 From: "Philipp A." Date: Tue, 4 Mar 2025 12:50:06 +0100 Subject: [PATCH 4/4] lint --- stdlib/functools.pyi | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/stdlib/functools.pyi b/stdlib/functools.pyi index 66ed626ef853..f786167e322d 100644 --- a/stdlib/functools.pyi +++ b/stdlib/functools.pyi @@ -152,9 +152,9 @@ class partialmethod(Generic[_T]): def __class_getitem__(cls, item: Any, /) -> GenericAlias: ... if sys.version_info >= (3, 11): - _RegType = type[Any] | types.UnionType + _RegType: TypeAlias = type[Any] | types.UnionType else: - _RegType = type[Any] + _RegType: TypeAlias = type[Any] class _SingleDispatchCallable(Generic[_T]): registry: types.MappingProxyType[Any, Callable[..., _T]] pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy