Skip to content

Honor false-valued callable wait strategies - #731

Closed
sricharanreddycheruku wants to merge 1 commit into
jd:mainfrom
sricharanreddycheruku:fix-falsey-wait-callables
Closed

sricharanreddycheruku wants to merge 1 commit into
jd:mainfrom
sricharanreddycheruku:fix-falsey-wait-callables

Conversation

@sricharanreddycheruku

@sricharanreddycheruku sricharanreddycheruku commented Oct 7, 2026 •

Copy link
Copy Markdown

A callable wait object whose __bool__ returns false or whose __len__ is zero is currently skipped by both Retrying and AsyncRetrying. Retries then use zero delay instead of the wait strategy's return value.

Check whether the setting is callable before evaluating its truth value. Callable strategies are always invoked; false-valued non-callables such as None and 0 continue to disable waiting, and truthy invalid settings still raise TypeError.

Adds regression tests through the public retry controllers for synchronous and asynchronous wait callables, zero-length callables, callables whose truth test raises, and compatibility with existing no-wait settings. Includes a Reno release note.

Validation on Python 3.12.14:

  • The new tests reproduce seven failures against the original implementation; all 15 cases pass with the fix.
  • uv run poe all passes: 199 tests, Ruff lint and formatting, strict mypy, 35 documentation doctests, and the HTML documentation build with warnings treated as errors.
  • uv run reno lint and git diff --check pass.

@jd

jd commented Oct 7, 2026

Copy link
Copy Markdown
Owner

Thanks for spotting this. I went with a different shape in #741: instead of casting self.wait to object to get past mypy, BaseRetrying.__init__ now matches the "no wait" values (None, 0, and sum([]) over no strategies) explicitly and replaces them with wait_none(). Both _run_wait then just call the strategy, so the falsy-callable case is fixed with no cast and no type: ignore, and a single regression test covers it. Closing in favor of #741.

@jd jd closed this Oct 7, 2026
mergify Bot pushed a commit that referenced this pull request Oct 7, 2026
BaseRetrying skipped the wait strategy whenever it was falsy, so a
callable strategy that is an empty container or defines __bool__ was
never called. Match the "no wait" values (None, 0, and sum([]) over no
strategies) explicitly, and replace them with wait_none() at construction
so both the sync and async loops just call the strategy. This drops the
truthy-bool type: ignore in both _run_wait.

Supersedes #731.


Change-Id: Ic5b013f36c168a6c387ad912840c4ab944c72f4b

Co-authored-by: Claude Opus 5.5 <[email protected]>
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.

2 participants