reportUnusedCoroutine.md
April 8, 2026 · View on GitHub
Overview
reportUnusedCoroutine is a Pylance and Pyright diagnostic that warns when a coroutine is defined but never awaited or used. This helps catch bugs where asynchronous code is silently ignored, which can lead to unexpected behavior.
Representative Issues
- #4163: Ensure consistency in the use of type stubs between Pyright's CLI and Pylance settings, especially with
useLibraryCodeForTypes. - #5200: Provide a configuration setting to allow users to customize diagnostic rule severities based on the type checking mode, improving the granularity of error reporting.
- #9579: Always ensure that coroutine calls are either awaited or explicitly checked for truthiness to avoid bugs where the coroutine is silently ignored.
Examples
Error:
import asyncio
async def fetch_data() -> str:
return "data"
async def main():
fetch_data() # Coroutine created but never awaited
Fix — await the coroutine:
import asyncio
async def fetch_data() -> str:
return "data"
async def main():
result = await fetch_data() # Now the coroutine runs
Common Fixes & Workarounds
- Always use
awaitwhen calling coroutines if you need their result. - If you intentionally do not await a coroutine, document this with a comment for clarity.
- Review your code for places where asynchronous functions are called but not awaited.
- Refer to the Pyright configuration documentation for details on configuring or disabling this diagnostic.
See Also
python.analysis.diagnosticSeverityOverrides— adjust or suppress this diagnosticpython.analysis.typeCheckingMode— controls which diagnostics are enabled by default