From 1e7235e3034596e483f94fcaaba9ca663a8c61a9 Mon Sep 17 00:00:00 2001 From: Julien Danjou Date: Wed, 25 Feb 2026 17:30:56 +0100 Subject: [PATCH] refactor: replace deprecated typing constructs with modern syntax Replace t.Optional, t.Union, and typing.Union with X | None / X | Y union syntax (PEP 604). Co-Authored-By: Claude Opus 4.6 Change-Id: I569081564348eac6cdfd934c8abcc92b144d35c6 --- tenacity/__init__.py | 8 ++++---- tenacity/wait.py | 2 +- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/tenacity/__init__.py b/tenacity/__init__.py index c6484a82..802bde7f 100644 --- a/tenacity/__init__.py +++ b/tenacity/__init__.py @@ -205,7 +205,7 @@ def __exit__( self, exc_type: type[BaseException] | None, exc_value: BaseException | None, - traceback: t.Optional["types.TracebackType"], + traceback: "types.TracebackType | None", ) -> bool | None: if exc_type is not None and exc_value is not None: self.retry_state.set_exception((exc_type, exc_value, traceback)) @@ -221,7 +221,7 @@ async def __aexit__( self, exc_type: type[BaseException] | None, exc_value: BaseException | None, - traceback: t.Optional["types.TracebackType"], + traceback: "types.TracebackType | None", ) -> bool | None: return self.__exit__(exc_type, exc_value, traceback) @@ -259,8 +259,8 @@ def __init__( def copy( self, sleep: t.Callable[[int | float], None] | object = _unset, - stop: t.Union["StopBaseT", object] = _unset, - wait: t.Union["WaitBaseT", object] = _unset, + stop: "StopBaseT | object" = _unset, + wait: "WaitBaseT | object" = _unset, retry: retry_base | object = _unset, before: t.Callable[["RetryCallState"], None] | object = _unset, after: t.Callable[["RetryCallState"], None] | object = _unset, diff --git a/tenacity/wait.py b/tenacity/wait.py index f06f3ccd..dd1090c6 100644 --- a/tenacity/wait.py +++ b/tenacity/wait.py @@ -34,7 +34,7 @@ def __call__(self, retry_state: "RetryCallState") -> float: def __add__(self, other: "wait_base") -> "wait_combine": return wait_combine(self, other) - def __radd__(self, other: "wait_base") -> typing.Union["wait_combine", "wait_base"]: + def __radd__(self, other: "wait_base") -> "wait_combine | wait_base": # make it possible to use multiple waits with the built-in sum function if other == 0: # type: ignore[comparison-overlap] return self