Skip to content

Commit

Permalink
Account for non-base objects in retries
Browse files Browse the repository at this point in the history
  • Loading branch information
hasier committed Jul 4, 2024
1 parent 33cd0e1 commit 5138fd8
Showing 1 changed file with 16 additions and 2 deletions.
18 changes: 16 additions & 2 deletions tenacity/retry.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,15 +30,29 @@ def __call__(self, retry_state: "RetryCallState") -> bool:
pass

def __and__(self, other: "retry_base") -> "retry_all":
return other.__rand__(self)
if isinstance(other, retry_base):
# Delegate to the other object to allow for specific
# implementations, such as asyncio
return other.__rand__(self)
return retry_all(other, self)

def __rand__(self, other: "retry_base") -> "retry_all":
# This is automatically invoked for inheriting classes,
# so it helps to keep the abstraction and delegate specific
# implementations, such as asyncio
return retry_all(other, self)

def __or__(self, other: "retry_base") -> "retry_any":
return other.__ror__(self)
if isinstance(other, retry_base):
# Delegate to the other object to allow for specific
# implementations, such as asyncio
return other.__ror__(self)
return retry_any(other, self)

def __ror__(self, other: "retry_base") -> "retry_any":
# This is automatically invoked for inheriting classes,
# so it helps to keep the abstraction and delegate specific
# implementations, such as asyncio
return retry_any(other, self)


Expand Down

0 comments on commit 5138fd8

Please sign in to comment.