fix: restore support for falsy wait values and callable + strategy - #694
Merged
mergify[bot] merged 1 commit intoAug 6, 2026
Conversation
Three runtime regressions from the mypy-strictness stack (#679, #677), all A/B verified against a2af454. None were caught by the test suite, and all three only fire once a retry actually happens, so happy-path callers see nothing until production. 1. `Retrying(wait=None)`, `wait=0` and `wait=sum([])` now raise `TypeError: 'NoneType' object is not callable` from inside `iter()`. #679 removed the `if self.wait:` guard on the grounds that `truthy-bool` proved it always true -- but that only holds for the *declared* type. Untyped callers pass `None`/`0` to mean "no wait", and `sum([])` over an empty strategy list returns the int 0. The `TypeError` is raised outside the attempt's try/except, so it escapes uncaught and destroys the caller's real exception. Restore the guard with a local `truthy-bool` suppression explaining why the "impossible" branch is reachable. `before`, `after`, `before_sleep` and `retry_error_callback` all kept their `is not None` guards; `wait` was the only one dropped. 2. `plain_callable + wait_strategy` now raises `TypeError`. `WaitBaseT` admits plain callables, and a function has no `__add__`, so this went through `wait_base.__radd__` -- which #677 narrowed to `int`. Widen it to `WaitBaseT | int` and build the `wait_combine` again. `5 + strategy` is still rejected, now via `NotImplemented` rather than a combination that fails later. The parameter stays `int` rather than `Literal[0]` because typeshed's `sum()` protocol requires `__radd__(x: int)`; narrowing it would make every `sum()` over strategies need a `type: ignore`. 3. `wait_combine.__call__` passed the state as `retry_state=`, which crashes on any `WaitBaseT` callable whose parameter has another name. Pass it positionally, as `BaseRetrying._run_wait` already does. Adds regression tests for all three plus the async path -- the original change shipped with no test covering any of them. Change-Id: Ia40c32a22cdac09cbfba4280fb0a7f0c2cb7b7e0
Owner
Author
|
This pull request is part of a Mergify stack:
|
jd
marked this pull request as ready for review
August 6, 2026 06:43
Contributor
Merge Queue Status
This pull request spent 7 seconds in the queue, including 1 second running CI. Required conditions to merge
|
mergify
Bot
deleted the
devs/jd/fix/wait-regressions/restore-support-falsy-wait-values-callable--a40c32a2
branch
August 6, 2026 06:44
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Three runtime regressions from the mypy-strictness stack (#679, #677), all
A/B verified against a2af454. None were caught by the test suite, and all
three only fire once a retry actually happens, so happy-path callers see
nothing until production.
Retrying(wait=None),wait=0andwait=sum([])now raiseTypeError: 'NoneType' object is not callablefrom insideiter().refactor: drop always-true truthiness checks and enable truthy-bool #679 removed the
if self.wait:guard on the grounds thattruthy-boolproved it always true -- but that only holds for the declared type.
Untyped callers pass
None/0to mean "no wait", andsum([])over anempty strategy list returns the int 0. The
TypeErroris raised outsidethe attempt's try/except, so it escapes uncaught and destroys the caller's
real exception. Restore the guard with a local
truthy-boolsuppressionexplaining why the "impossible" branch is reachable.
before,after,before_sleepandretry_error_callbackall kept theiris not Noneguards;
waitwas the only one dropped.plain_callable + wait_strategynow raisesTypeError.WaitBaseTadmits plain callables, and a function has no
__add__, so this wentthrough
wait_base.__radd__-- which fix: annotate wait_base.__radd__ as taking the int seed from sum() #677 narrowed toint. Widen it toWaitBaseT | intand build thewait_combineagain.5 + strategyisstill rejected, now via
NotImplementedrather than a combination thatfails later. The parameter stays
intrather thanLiteral[0]becausetypeshed's
sum()protocol requires__radd__(x: int); narrowing itwould make every
sum()over strategies need atype: ignore.wait_combine.__call__passed the state asretry_state=, which crasheson any
WaitBaseTcallable whose parameter has another name. Pass itpositionally, as
BaseRetrying._run_waitalready does.Adds regression tests for all three plus the async path -- the original
change shipped with no test covering any of them.