jd / tenacity

Retrying library for Python
http://tenacity.readthedocs.io
Apache License 2.0
6.82k stars 283 forks source link

Incrementally build iter actions list #434

Closed hasier closed 10 months ago

hasier commented 10 months ago

First PR after breaking down https://github.com/jd/tenacity/pull/433

An attempt at DRYing the iter() function in order to support async callbacks.

The approach I have taken is to build a list of actions that iter() needs to go through, where each action is just a piece of the whole current logic, and each step can further extend the list of actions. 3 pieces have been taken out to redefine in specific Retrying implementations, i.e. asyncio. This way we can make sure we use coroutines for those calls, as well as dynamically wrapping each function as a coroutine, allowing for both sync and async strategies and callbacks.

mergify[bot] commented 10 months ago

⚠️ No release notes detected. Please make sure to use reno to add a changelog entry.

hasier commented 10 months ago

@jd I noticed black checks are also failing in CI, but I think there is an incompatibility between black and pep8. The first one is trying to remove some whitespace, whereas the latter complains it wants the whitespace back. Is this something you can look at in the main branch maybe?

jd commented 10 months ago

I switched the project to ruff to solve this.

hasier commented 10 months ago

I switched the project to ruff to solve this.

Thanks @jd! Just re-formatted the changes with ruff 😊

mergify[bot] commented 10 months ago

⚠️ No release notes detected. Please make sure to use reno to add a changelog entry.

hasier commented 10 months ago

Sorry @jd just saw that dataclass(slots=True) is only available from Python 3.10 onwards 🤦 I just fixed it by conditionally adding it, hopefully that looks ok to you! https://github.com/jd/tenacity/pull/434/commits/5b11340f997b8db6e48728006bd0dc6257c446fe

hasier commented 10 months ago

@jd how would you want to go about the chain of PRs? Do you want me to add a reno note here and merge this set of changes first, or would you prefer to merge the 2 other PRs here, then just merge 1 big PR to main? Happy to follow whichever process you prefer, let me know if you want me to update the PRs in any specific way.

jd commented 10 months ago

As long as there is no external changes, we can skip the changelog entry.