Skip to content

Handle synchronous sleep callbacks in AsyncRetrying - #723

Closed
Eric3-jp wants to merge 1 commit into
jd:mainfrom
Eric3-jp:fix/synchronous-async-sleep
Closed

Eric3-jp wants to merge 1 commit into
jd:mainfrom
Eric3-jp:fix/synchronous-async-sleep

Conversation

@Eric3-jp

Copy link
Copy Markdown

AsyncRetrying accepts a sleep callback returning either None or an awaitable in its public type signature, but both retry loops unconditionally await its result. A synchronous callback such as sleep=delays.append therefore raises TypeError: object NoneType can't be used in 'await' expression after the first failed attempt.

Call the callback once and await its result only when it is not None. Both direct calls and async iteration use the same helper. Async functions and ordinary functions returning awaitables keep their existing behavior, including the default asyncio/Trio sleep implementation. The change also documents the synchronous callback behavior and includes a release note.

The six regression/compatibility cases exercise both entry points with synchronous callbacks, async callbacks, and ordinary functions returning awaitables. They verify completion, requested delays, attempt counts, and accumulated idle time. Before the fix, the two synchronous cases fail and the four awaitable cases pass.

Validation on Linux (WSL), CPython 3.11.16:

  • poe all: Ruff 0.16.5 lint and formatting, strict Mypy 2.3.1 (19 source files), all 190 tests, all 35 Sphinx doctests, and the Sphinx HTML build with warnings treated as errors passed.
  • git diff --check passed.

AI assistance: this contribution was investigated, implemented, and locally tested with OpenAI Codex.

@Eric3-jp Eric3-jp closed this by deleting the head repository Sep 23, 2026
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.

1 participant