-
Notifications
You must be signed in to change notification settings - Fork 3k
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
Replace tenacity.retry with our own decorator #12705
Conversation
9f64176
to
1ceaed9
Compare
CI is failing as typing-extensions doesn't support Python 3.13 (at least not for |
As you have no runtime need for these type hints, a workaround is to put the type annotation constructions behind an |
I literally contribute to mypyc and yet I somehow completely forgot about that trick. Gosh, that's what I get for writing code when I'm too tired. Thanks for the reminder! (*) I'm not sure if the use of |
This seems simple enough, but do we have analysis on how the decorator compares to tenacity’s implementation? Are there edge cases? |
2d97e4d
to
37f233d
Compare
I did briefly read through tenacity's source code to get a feel for how it works (especially in regards to the time limit), but I haven't examined it carefully. However, I have written a decent set of unit tests for my decorator. Notably, they still all pass when testing tenacity's from tenacity import wait_fixed, stop_after_delay as _stop_after_delay, retry as _retry
def retry(wait, stop_after_delay):
return _retry(wait=wait_fixed(wait), stop=_stop_after_delay(stop_after_delay), reraise=True) I can take a closer look at tenacity's implementation if you'd like, but I think these tests demonstrate that the two decorators are functionally equivalent in the areas that matter. |
31812dc
to
5118b5d
Compare
Windows' such a joy, sigh ✨ |
This is reasonably close to be ready for review. I do want to make some more minor changes to the tests, but CI is going to keep failing until #12732 is merged. |
5118b5d
to
a458b5d
Compare
Oh for goodness sake, Python 3.8's |
Tenacity is a 1600+ LOC dependency which is only used for a convenient `@retry` decorator... which is used a grand total of two times. This is a lot of code for what can be trivially reimplemented by us. This also incidentally improves startup performance as tenacity imports asyncio which is expensive and unnecessary for us.
a458b5d
to
396fdf0
Compare
Alright, this should be ready for review now that #12804 is in. I know this patch looks big, but the vast majority of the additions is from the unit tests. The retry utility altogether is only 41 lines long. See also #12705 (comment) for commentary on the equivalency between this new decorator and |
Tenacity is a 1600+ LOC dependency which is only used for a convenient
@retry
decorator... which is used a grand total of two times. This is a lot of code for what can be trivially reimplemented by us.This also incidentally improves startup performance as tenacity imports asyncio which is expensive and unnecessary for us.
Resolves #10822.