Skip to main content

Use High-Level `asyncio` API Functions to Create Tasks


ImportanceReview GuidanceRequires Scanning Tool
LowMerge After Cursory ReviewNo

The asyncio documentation explicitly discourages manual instantiation of a Task instance and instead recommends calling create_task. This keeps your code in line with recommended best practices and promotes maintainability.

Our changes look like the following:

 import asyncio

- task = asyncio.Task(my_coroutine(), name="my task")
+ task = asyncio.create_task(my_coroutine(), name="my task")

If you have feedback on this codemod, please let us know!


Why is this codemod marked as Merge After Cursory Review?

Manual instantiation of asyncio.Task is discouraged. We believe this change is safe and will not cause any issues.

Codemod Settings