Skip to content

Warn about unused Awaitables (and potentially other objects) #2499

@JelleZijlstra

Description

@JelleZijlstra

This code:

async def f() -> None:
    pass
async def g() -> None:
    f()

is incorrect because f() isn't awaited. This will produce a runtime warning with the right debug settings, but mypy doesn't give any errors.

It would be nice if mypy could catch this, since I think it's a pretty common error in async code. This could be generalized to warning on other types or function return values that shouldn't be ignored (maybe open?), similar to __attribute__((warn_unused_result)) in GCC.

Editing in a 2025 update to the OP

Try --enable-error-code unused-awaitable --enable-error-code truthy-bool and see if that catches the thing you want it to catch

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions