Skip to content

Conversation

@akapps
Copy link
Contributor

@akapps akapps commented Jan 29, 2021

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.

Fixes issue #233

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.
@akapps
Copy link
Contributor Author

akapps commented Feb 1, 2021

I've run black against my changes - now the CI's green finally 😌

jd
jd previously requested changes Feb 1, 2021
Copy link
Owner

@jd jd left a 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

Comment on lines 265 to 266
def first_set(first, second):
return second if first is _unset else first
Copy link
Owner

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.

Copy link
Contributor Author

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.

Copy link
Owner

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.

self.assertEqual(h(), "Hello")


class TestRetryWith(unittest.TestCase):
Copy link
Owner

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

Comment on lines 1056 to 1063
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)
Copy link
Owner

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
@mergify mergify bot dismissed jd’s stale review February 1, 2021 12:39

Pull request has been modified.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants