当前位置: 首页>>代码示例 >>用法及示例精选 >>正文


Python typing.Coroutine用法及代码示例


用法:

class typing.Coroutine(Awaitable[V_co], Generic[T_co, T_contra, V_co])

collections.abc.Coroutine 的通用版本。类型变量的方差和顺序对应于Generator,例如:

from collections.abc import Coroutine
c: Coroutine[list[str], str, int]  # Some coroutine defined elsewhere
x = c.send('hi')                   # Inferred type of 'x' is list[str]
async def bar() -> None:
    y = await c                    # Inferred type of 'y' is int

版本 3.5.3 中的新函数。

自 3.9 版后已弃用:collections.abc.Coroutine现在支持[].看PEP 585通用别名类型.

相关用法


注:本文由纯净天空筛选整理自python.org大神的英文原创作品 typing.Coroutine。非经特殊声明,原始代码版权归原作者所有,本译文未经允许或授权,请勿转载或复制。