Feat: add retry_unless_exception_cause_type (#625)#626
Open
Kitan-Dara06 wants to merge 6 commits intojd:mainfrom
Open
Feat: add retry_unless_exception_cause_type (#625)#626Kitan-Dara06 wants to merge 6 commits intojd:mainfrom
Kitan-Dara06 wants to merge 6 commits intojd:mainfrom
Conversation
|
The new class LGTM, but I don't really think the inverse overload behaves as one would expect to make it useful. |
rgullik1
suggested changes
Mar 11, 2026
Comment on lines
+60
to
+63
| def __invert__(self) -> "retry_base": | ||
| """Return a retry strategy that is the logical inverse of this one.""" | ||
| return _retry_inverted(self) | ||
|
|
There was a problem hiding this comment.
I don't think the invert overload will be useful, please remove
Comment on lines
+68
to
+81
| class _retry_inverted(retry_base): | ||
| """Retry strategy that inverts the decision of another retry strategy.""" | ||
|
|
||
| def __init__(self, retry: "retry_base") -> None: | ||
| self.retry = retry | ||
|
|
||
| def __call__(self, retry_state: "RetryCallState") -> bool: | ||
| return not self.retry(retry_state) | ||
|
|
||
| def __invert__(self) -> "retry_base": | ||
| # Double inversion returns the original. | ||
| return self.retry | ||
|
|
||
|
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This PR introduces the retry_unless_exception_cause_type class to mirror the existing retry_unless_exception_type logic. It halts the retry loop immediately if the root cause of the raised exception matches the specified type.
Related Issue:
Resolves #625
Testing:
[x] Implemented core logic in tenacity/retry.py
[x] Added unit tests in tests/test_tenacity.py confirming the retry loop halts on a matched cause and continues otherwise.
[x] Passed all local pytest checks (149/149).