-
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
base: main
Are you sure you want to change the base?
Conversation
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.
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. |
37f233d
to
31812dc
Compare
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. |
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.