From 17019aea6d76fcb55ed6aa7f5d8fa1d927716227 Mon Sep 17 00:00:00 2001 From: jorenham Date: Tue, 1 Sep 2026 17:13:26 +0200 Subject: [PATCH] Explicitly mark type aliases as `typing.TypeAlias` --- tenacity/_utils.py | 2 +- tenacity/asyncio/retry.py | 2 +- tenacity/retry.py | 2 +- tenacity/stop.py | 2 +- tenacity/wait.py | 4 +++- 5 files changed, 7 insertions(+), 5 deletions(-) diff --git a/tenacity/_utils.py b/tenacity/_utils.py index 96c9e99f..0c62dea5 100644 --- a/tenacity/_utils.py +++ b/tenacity/_utils.py @@ -101,7 +101,7 @@ def get_callback_name(cb: typing.Callable[..., typing.Any]) -> str: return ".".join(segments) -time_unit_type = int | float | timedelta +time_unit_type: typing.TypeAlias = int | float | timedelta # noqa: PYI042 def to_seconds(time_unit: time_unit_type) -> float: diff --git a/tenacity/asyncio/retry.py b/tenacity/asyncio/retry.py index c2480706..30d546f4 100644 --- a/tenacity/asyncio/retry.py +++ b/tenacity/asyncio/retry.py @@ -56,7 +56,7 @@ def __ror__( # type: ignore[misc,override] return retry_any(other, self) -RetryBaseT = ( +RetryBaseT: typing.TypeAlias = ( async_retry_base | typing.Callable[["RetryCallState"], typing.Awaitable[bool]] ) diff --git a/tenacity/retry.py b/tenacity/retry.py index dc7beab6..ce6f30cb 100644 --- a/tenacity/retry.py +++ b/tenacity/retry.py @@ -60,7 +60,7 @@ def __ror__(self, other: "RetryBaseT") -> "retry_any": return retry_any(other, self) -RetryBaseT = retry_base | typing.Callable[["RetryCallState"], bool] +RetryBaseT: typing.TypeAlias = retry_base | typing.Callable[["RetryCallState"], bool] class _retry_never(retry_base): diff --git a/tenacity/stop.py b/tenacity/stop.py index c1f51ea9..04689238 100644 --- a/tenacity/stop.py +++ b/tenacity/stop.py @@ -39,7 +39,7 @@ def __or__(self, other: "stop_base") -> "stop_any": return stop_any(self, other) -StopBaseT = stop_base | typing.Callable[["RetryCallState"], bool] +StopBaseT: typing.TypeAlias = stop_base | typing.Callable[["RetryCallState"], bool] class stop_any(stop_base): diff --git a/tenacity/wait.py b/tenacity/wait.py index 6607e4fd..d0e91dec 100644 --- a/tenacity/wait.py +++ b/tenacity/wait.py @@ -55,7 +55,9 @@ def __radd__(self, other: "WaitBaseT | int") -> "wait_combine | wait_base": return wait_combine(self, other) -WaitBaseT = wait_base | typing.Callable[["RetryCallState"], float | int] +WaitBaseT: typing.TypeAlias = ( + wait_base | typing.Callable[["RetryCallState"], float | int] +) class wait_fixed(wait_base):