Skip to content

Add unused-awaitable diagnostic (detect unawaited coroutines) #2791

@oliverlambson

Description

@oliverlambson

It would be useful for ty to detect cases where a coroutine is called but never awaited — equivalent to mypy's unused-awaitable error code.

async def fetch_data() -> str:
    return "data"

async def main() -> None:
    fetch_data()  # should warn: coroutine is not awaited
    result = fetch_data()  # should warn: result is Coroutine, not str

Python emits RuntimeWarning: coroutine was never awaited at runtime, but catching this statically is much more valuable — especially for large async codebases or sync-to-async migrations where missed awaits are easy to introduce and hard to spot.

Prior art

  • mypy: unused-awaitable (opt-in via --enable-error-code=unused-awaitable)
  • ruff: astral-sh/ruff#9833 (open, but maintainer comments suggest should be here)
  • ty: #198 listed this among mypy error codes to reimplement, but was closed as too broad with a suggestion to file individual issues (no one filed for this though, so I am)

Suggested behavior

I would assume opt-in/warning severity

Metadata

Metadata

Assignees

Labels

asyncIssues related to checking code using async/awaitlintLabel for features that we would implement as lint rules, not core type checker features

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions