Skip to content

Incrementally build iter actions list#434

Merged
mergify[bot] merged 7 commits into
jd:mainfrom
hasier:refactor-iter-actions
Feb 6, 2024
Merged

Incrementally build iter actions list#434
mergify[bot] merged 7 commits into
jd:mainfrom
hasier:refactor-iter-actions

Conversation

@hasier

@hasier hasier commented Feb 2, 2024

Copy link
Copy Markdown
Contributor

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.

@mergify

mergify Bot commented Feb 2, 2024

Copy link
Copy Markdown
Contributor

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

Comment thread tenacity/__init__.py Outdated
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
Copy Markdown
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
Copy Markdown
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

hasier commented Feb 3, 2024

Copy link
Copy Markdown
Contributor Author

@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

jd commented Feb 3, 2024

Copy link
Copy Markdown
Owner

I switched the project to ruff to solve this.

@hasier

hasier commented Feb 5, 2024

Copy link
Copy Markdown
Contributor Author

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
@mergify

mergify Bot commented Feb 5, 2024

Copy link
Copy Markdown
Contributor

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

Comment thread tenacity/__init__.py Outdated
Comment thread tenacity/__init__.py Outdated
@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

hasier commented Feb 5, 2024

Copy link
Copy Markdown
Contributor Author

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

hasier commented Feb 5, 2024

Copy link
Copy Markdown
Contributor Author

@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

jd commented Feb 6, 2024

Copy link
Copy Markdown
Owner

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
@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