From 22ed3f611e8bdcd3e0c1dc137ef07924e4af5468 Mon Sep 17 00:00:00 2001 From: hereisasound Date: Wed, 19 Jun 2024 13:40:51 +0300 Subject: [PATCH 1/4] Change functools.Wrapped call signature from wrapper to wrapped --- stdlib/functools.pyi | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/stdlib/functools.pyi b/stdlib/functools.pyi index 9957fa8f1634..ca102c35ce8e 100644 --- a/stdlib/functools.pyi +++ b/stdlib/functools.pyi @@ -85,7 +85,7 @@ WRAPPER_UPDATES: tuple[Literal["__dict__"]] class _Wrapped(Generic[_PWrapped, _RWrapped, _PWrapper, _RWrapper]): __wrapped__: Callable[_PWrapped, _RWrapped] - def __call__(self, *args: _PWrapper.args, **kwargs: _PWrapper.kwargs) -> _RWrapper: ... + def __call__(self, *args: _PWrapped.args, **kwargs: _PWrapped.kwargs) -> _RWrapped: ... # as with ``Callable``, we'll assume that these attributes exist __name__: str __qualname__: str From 7ec613c6710c9db9908962151c60bbc1608aba97 Mon Sep 17 00:00:00 2001 From: hereisasound Date: Fri, 21 Jun 2024 18:11:01 +0300 Subject: [PATCH 2/4] Add special wraps for wrapped method --- stdlib/functools.pyi | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/stdlib/functools.pyi b/stdlib/functools.pyi index ca102c35ce8e..fd6fb849d4af 100644 --- a/stdlib/functools.pyi +++ b/stdlib/functools.pyi @@ -90,9 +90,19 @@ class _Wrapped(Generic[_PWrapped, _RWrapped, _PWrapper, _RWrapper]): __name__: str __qualname__: str +class _WrappedMethod(Generic[_PWrapped, _RWrapped, _PWrapper, _RWrapper]): + __wrapped__: Callable[_PWrapped, _RWrapped] + def __call__(self, *args: _PWrapped.args, **kwargs: _PWrapped.kwargs) -> _RWrapped: ... + # as with ``Callable``, we'll assume that these attributes exist + __name__: str + __qualname__: str + class _Wrapper(Generic[_PWrapped, _RWrapped]): def __call__(self, f: Callable[_PWrapper, _RWrapper]) -> _Wrapped[_PWrapped, _RWrapped, _PWrapper, _RWrapper]: ... +class _MethodWrapper(Generic[_PWrapped, _RWrapped]): + def __call__(self, f: Callable[_PWrapper, _RWrapper]) -> _WrappedMethod[_PWrapped, _RWrapped, _PWrapper, _RWrapper]: ... + if sys.version_info >= (3, 12): def update_wrapper( wrapper: Callable[_PWrapper, _RWrapper], @@ -100,6 +110,12 @@ if sys.version_info >= (3, 12): assigned: Sequence[str] = ("__module__", "__name__", "__qualname__", "__doc__", "__annotations__", "__type_params__"), updated: Sequence[str] = ("__dict__",), ) -> _Wrapped[_PWrapped, _RWrapped, _PWrapper, _RWrapper]: ... + def wraps( + wrapped: Callable[Concatenate[Self, _PWrapped], _RWrapped], + assigned: Sequence[str] = ( + "__module__", "__name__", "__qualname__", "__doc__", "__annotations__", "__type_params__"), + updated: Sequence[str] = ("__dict__",), + ) -> _MethodWrapper[_PWrapped, _RWrapped]: ... def wraps( wrapped: Callable[_PWrapped, _RWrapped], assigned: Sequence[str] = ("__module__", "__name__", "__qualname__", "__doc__", "__annotations__", "__type_params__"), @@ -113,6 +129,12 @@ else: assigned: Sequence[str] = ("__module__", "__name__", "__qualname__", "__doc__", "__annotations__"), updated: Sequence[str] = ("__dict__",), ) -> _Wrapped[_PWrapped, _RWrapped, _PWrapper, _RWrapper]: ... + def wraps( + wrapped: Callable[Concatenate[Self, _PWrapped], _RWrapped], + assigned: Sequence[str] = ( + "__module__", "__name__", "__qualname__", "__doc__", "__annotations__", "__type_params__"), + updated: Sequence[str] = ("__dict__",), + ) -> _MethodWrapper[_PWrapped, _RWrapped]: ... def wraps( wrapped: Callable[_PWrapped, _RWrapped], assigned: Sequence[str] = ("__module__", "__name__", "__qualname__", "__doc__", "__annotations__"), From 36931fbcf5008ec9a7ac8dde39d98e39a7e1c71e Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Fri, 21 Jun 2024 15:12:39 +0000 Subject: [PATCH 3/4] [pre-commit.ci] auto fixes from pre-commit.com hooks --- stdlib/functools.pyi | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/stdlib/functools.pyi b/stdlib/functools.pyi index fd6fb849d4af..fb2d8376cd15 100644 --- a/stdlib/functools.pyi +++ b/stdlib/functools.pyi @@ -112,8 +112,7 @@ if sys.version_info >= (3, 12): ) -> _Wrapped[_PWrapped, _RWrapped, _PWrapper, _RWrapper]: ... def wraps( wrapped: Callable[Concatenate[Self, _PWrapped], _RWrapped], - assigned: Sequence[str] = ( - "__module__", "__name__", "__qualname__", "__doc__", "__annotations__", "__type_params__"), + assigned: Sequence[str] = ("__module__", "__name__", "__qualname__", "__doc__", "__annotations__", "__type_params__"), updated: Sequence[str] = ("__dict__",), ) -> _MethodWrapper[_PWrapped, _RWrapped]: ... def wraps( @@ -131,8 +130,7 @@ else: ) -> _Wrapped[_PWrapped, _RWrapped, _PWrapper, _RWrapper]: ... def wraps( wrapped: Callable[Concatenate[Self, _PWrapped], _RWrapped], - assigned: Sequence[str] = ( - "__module__", "__name__", "__qualname__", "__doc__", "__annotations__", "__type_params__"), + assigned: Sequence[str] = ("__module__", "__name__", "__qualname__", "__doc__", "__annotations__", "__type_params__"), updated: Sequence[str] = ("__dict__",), ) -> _MethodWrapper[_PWrapped, _RWrapped]: ... def wraps( From dc4ff369b7456dc4fff7789fc24089fbed79cb25 Mon Sep 17 00:00:00 2001 From: hereisasound Date: Fri, 21 Jun 2024 18:15:00 +0300 Subject: [PATCH 4/4] Revert back _Wrapped class --- stdlib/functools.pyi | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/stdlib/functools.pyi b/stdlib/functools.pyi index fb2d8376cd15..6c96cf14117b 100644 --- a/stdlib/functools.pyi +++ b/stdlib/functools.pyi @@ -85,7 +85,7 @@ WRAPPER_UPDATES: tuple[Literal["__dict__"]] class _Wrapped(Generic[_PWrapped, _RWrapped, _PWrapper, _RWrapper]): __wrapped__: Callable[_PWrapped, _RWrapped] - def __call__(self, *args: _PWrapped.args, **kwargs: _PWrapped.kwargs) -> _RWrapped: ... + def __call__(self, *args: _PWrapper.args, **kwargs: _PWrapper.kwargs) -> _RWrapped: ... # as with ``Callable``, we'll assume that these attributes exist __name__: str __qualname__: str