Skip to content
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

Incrementally build iter actions list #434

Merged
merged 7 commits into from
Feb 6, 2024
Merged

Conversation

hasier
Copy link
Contributor

@hasier hasier commented Feb 2, 2024

First PR after breaking down #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.

Copy link
Contributor

mergify bot commented Feb 2, 2024

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

try:
return self._local.iter_state # type: ignore[no-any-return]
except AttributeError:
self._local.iter_state = t.cast(t.Dict[str, t.Any], {})
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we have something either more structured or split?
I am no fan of having a dict with Any and random keys TBH.

At least a TypedDict?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sounds fair, wdyt? 538686b

tbh I just copied the approach from the statistics property, and I was tempted to change the local() implementation for a ContextVar and maybe introducing dataclasses, but seemed like a bit too much to do together with these changes. Maybe something to tackle separately if that's something you'd like to see.

@hasier
Copy link
Contributor Author

hasier commented Feb 3, 2024

@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
Copy link
Owner

jd commented Feb 3, 2024

I switched the project to ruff to solve this.

@hasier
Copy link
Contributor Author

hasier commented Feb 5, 2024

I switched the project to ruff to solve this.

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

@hasier hasier requested a review from jd February 5, 2024 11:06
Copy link
Contributor

mergify bot commented Feb 5, 2024

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

tenacity/__init__.py Outdated Show resolved Hide resolved
tenacity/__init__.py Outdated Show resolved Hide resolved
@hasier hasier requested a review from jd February 5, 2024 14:59
jd
jd previously approved these changes Feb 5, 2024
@mergify mergify bot dismissed jd’s stale review February 5, 2024 15:27

Pull request has been modified.

@hasier
Copy link
Contributor Author

hasier commented Feb 5, 2024

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! 5b11340

@hasier
Copy link
Contributor Author

hasier commented Feb 5, 2024

@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 jd added the no-changelog No changelog needed label Feb 6, 2024
@jd
Copy link
Owner

jd commented Feb 6, 2024

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

@mergify mergify bot merged commit 17aefd9 into jd:main Feb 6, 2024
9 of 10 checks passed
@hasier hasier mentioned this pull request Feb 6, 2024
@hasier hasier mentioned this pull request Mar 18, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
no-changelog No changelog needed
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants