如何使用Python类型提示注释上下文管理器?
import typing
@contextlib.contextmanager
def foo() -> ???:
yield
Run Code Online (Sandbox Code Playgroud)
关于contextlib的文档并未提及类型.
关于typing.ContextManager的文档也不是那么有用.
还有typing.Generator,至少有一个例子.这是否意味着我应该使用typing.Generator[None, None, None]而不是typing.ContextManager?
import typing
@contextlib.contextmanager
def foo() -> typing.Generator[None, None, None]:
yield
Run Code Online (Sandbox Code Playgroud)