From 9cebbaa10934634f7197d2c529fdf1a86107b6fa Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fr=C3=A9d=C3=A9ric=20Perrin?= Date: Mon, 17 May 2021 08:55:25 +0100 Subject: [PATCH 1/2] Fix decorator in retry package --- stubs/retry/retry/api.pyi | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/stubs/retry/retry/api.pyi b/stubs/retry/retry/api.pyi index 88f274b9d1c3..d50435eff884 100644 --- a/stubs/retry/retry/api.pyi +++ b/stubs/retry/retry/api.pyi @@ -1,9 +1,11 @@ from logging import Logger -from typing import Any, Callable, Dict, Optional, Sequence, Tuple, Type, TypeVar, Union +from typing import Any, Callable, Dict, Optional, Protocol, Sequence, Tuple, Type, TypeVar, Union -_T = TypeVar("_T", bound=Callable[..., Any]) -_Decorator = Callable[[_T], _T] _R = TypeVar("_R") +_T = TypeVar("_T", bound=Callable[..., Any]) + +class _Decorator(Protocol): + def __call__(self, __x: _T) -> _T: ... def retry_call( f: Callable[..., _R], @@ -25,4 +27,4 @@ def retry( backoff: float = ..., jitter: Union[Tuple[float, float], float] = ..., logger: Optional[Logger] = ..., -) -> _Decorator[_T]: ... +) -> _Decorator: ... From 4d68cb9f85f086dea40e6489b54b7e258d4988a5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fr=C3=A9d=C3=A9ric=20Perrin?= Date: Mon, 17 May 2021 11:17:23 +0100 Subject: [PATCH 2/2] Use IdentityFunction for decorator return type --- stubs/retry/retry/api.pyi | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) diff --git a/stubs/retry/retry/api.pyi b/stubs/retry/retry/api.pyi index d50435eff884..cf52a9ef908d 100644 --- a/stubs/retry/retry/api.pyi +++ b/stubs/retry/retry/api.pyi @@ -1,11 +1,8 @@ +from _typeshed import IdentityFunction from logging import Logger -from typing import Any, Callable, Dict, Optional, Protocol, Sequence, Tuple, Type, TypeVar, Union +from typing import Any, Callable, Dict, Optional, Sequence, Tuple, Type, TypeVar, Union _R = TypeVar("_R") -_T = TypeVar("_T", bound=Callable[..., Any]) - -class _Decorator(Protocol): - def __call__(self, __x: _T) -> _T: ... def retry_call( f: Callable[..., _R], @@ -27,4 +24,4 @@ def retry( backoff: float = ..., jitter: Union[Tuple[float, float], float] = ..., logger: Optional[Logger] = ..., -) -> _Decorator: ... +) -> IdentityFunction: ...