Skip to content

fix(wait): call wait_chain strategies positionally - #781

Open
Omarinho12345 wants to merge 1 commit into
jd:mainfrom
Omarinho12345:fix/wait-chain-callable
Open

Omarinho12345 wants to merge 1 commit into
jd:mainfrom
Omarinho12345:fix/wait-chain-callable

Conversation

@Omarinho12345

Copy link
Copy Markdown

Problem

wait_chain() called the selected wait strategy as wait_func(retry_state=retry_state). A plain callable is a valid WaitBaseT wait strategy everywhere else — wait=, wait_combine(), wait_fixed() + callable, sum([...]) — and those paths pass the state positionally, so a callable whose parameter is not named exactly retry_state worked in all of them but raised TypeError inside wait_chain():

wait_chain(wait_fixed(0), lambda _: 2.0)
# TypeError: <lambda>() got an unexpected keyword argument 'retry_state'

The same callable works with wait_combine(wait_fixed(0), ...) and wait_fixed(0) + ....

Fix

  • Invoke chain strategies positionally, matching wait_combine and BaseRetrying._run_wait.
  • Widen wait_chain.__init__ to *strategies: WaitBaseT so the signature reflects what is actually supported.
  • Add test_wait_chain_accepts_callable_strategy, which fails on current main and passes with the change.

No behaviour change for wait_base subclasses, which accept the state as a keyword.

Tests

python -m pytest tests/test_tenacity.py -q   # 143 passed, 15 subtests passed
python -m ruff check tenacity tests         # All checks passed
python -m ruff format --check tenacity tests

Fixes #780

A plain callable is a valid wait strategy for wait=, wait_combine()
and wait_fixed() + callable, all of which pass the state positionally.
wait_chain() passed 
etry_state by keyword, so it raised TypeError on
any callable whose parameter is not named 
etry_state.

Fixes jd#780
@mergify

mergify Bot commented Nov 19, 2026

Copy link
Copy Markdown
Contributor

Tick the box to add this pull request to the merge queue (same as @mergifyio queue). If it does not match the queue conditions yet, it enters the queue once it does.

  • Queue this pull request once it meets the queue conditions

@Ekko82 Ekko82 left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

I ran four focused cases on Windows x64 with CPython 3.13.9 using the default sleepers and zero delays. With a positional-only callable as the final wait_chain strategy, both Retrying and AsyncRetrying raised TypeError after attempt 2 on the base because the chain passed retry_state by keyword. On 4264fa5, both returned the result on attempt 4. The callable received the failure state for attempts 2 and 3, exercising reuse of the final strategy.

The equivalent wait_fixed controls passed on both revisions. I ran these cases outside the full test suite.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

wait_chain passes retry_state as keyword, breaking callable wait strategies

3 participants