Runtime Utility Functions
types.coroutine()
Adapt a generator function for generator-based coroutine use. Its generator can be awaited even without implementing the ordinary __await__ attribute. Prefer async def for new coroutine definitions.
Formal Syntax & Structure
python syntaxpython
types.coroutine(func,)Parameters & Attributes
| Name | Type | Description |
|---|---|---|
| func | callable | Generator function or callable to adapt. |
Return Value
callable
The callable result described above.
Working Example
Example Snippetpython
import typesimport asyncio@types.coroutinedef legacy(): if False: yield return 7async def main(): return await legacy()print(asyncio.run(main()))