Skip to content

tenacity.retry(sleep=...) fails type-checking with async sleep function #553

@cjwatson

Description

@cjwatson

Since tenacity 9.1.3, the following program (reduced from real code) fails to type-check:

import asyncio

import tenacity


async def _tenacity_sleep(delay: float) -> None:
    await asyncio.sleep(delay)


@tenacity.retry(sleep=_tenacity_sleep)
async def do_wait_for_messages() -> None:
    pass
$ mypy --strict t.py
t.py:10: error: Argument 1 has incompatible type "Callable[[], Coroutine[Any, Any, None]]"; expected "Callable[[], Awaitable[Never]]"  [arg-type]
Found 1 error in 1 file (checked 1 source file)

The corresponding sync variant still type-checks fine.

I assume this has something to do with the new return type annotation in the async overload variant introduced by #551, but I haven't quite been able to puzzle it out. Maybe @Zac-HD can help, since this was their change?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions