-
-
Notifications
You must be signed in to change notification settings - Fork 303
Copy whole internal state when retry_with (#233) #278
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
Both `retry_error_cls` and `retry_error_callback` were missing from the copy, resulting in a copy that presents a different behavior than the original function.
|
I've run black against my changes - now the CI's green finally 😌 |
jd
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you! LGTM just one minor thing in test
tenacity/__init__.py
Outdated
| def first_set(first, second): | ||
| return second if first is _unset else first |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There should be no need to redefine this on each call, you can just move it as a static method.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you for the review.
My thinking was that since the method is very limited in scope, making it a local function would be clearer to the reader than defining it at the module level. And copy() being called probably not that often, the performance overhead seemed acceptable.
Making a static method is too cumbersome and defeats the purpose of the function IMHO:
reraise=BaseRetrying._first_set(reraise, self.reraise),
retry_error_cls=BaseRetrying._first_set(
retry_error_cls, self.retry_error_cls
),In the end I moved it as a module-level function, if you're OK with that.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Having it as a module-level function disallow inheritance to override the method.
I don't think it's a big deal though, so that's fine.
tenacity/tests/test_tenacity.py
Outdated
| self.assertEqual(h(), "Hello") | ||
|
|
||
|
|
||
| class TestRetryWith(unittest.TestCase): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
since we're now using pytest you can get away with unittest altogether
tenacity/tests/test_tenacity.py
Outdated
| try: | ||
| _retryable.retry_with(stop=tenacity.stop_after_attempt(2))() | ||
| self.fail("Expected ValueError") | ||
| except Exception as exc: # noqa: B902 | ||
| self.assertIsInstance( | ||
| exc, ValueError, "Should remap to specific exception type" | ||
| ) | ||
| print(exc) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
use pytest.raises
- define `_first_set` only once - get away with unittest - use pytest.raises
Both
retry_error_clsandretry_error_callbackwere missing fromthe copy, resulting in a copy that presents a different behavior
than the original function.
Fixes issue #233