Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Correct return type of asynccontextmanager in 3.10 #6634

Merged
merged 2 commits into from
Dec 20, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 13 additions & 8 deletions stdlib/contextlib.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -33,14 +33,25 @@ _P = ParamSpec("_P")
_ExitFunc = Callable[[Optional[Type[BaseException]], Optional[BaseException], Optional[TracebackType]], bool]
_CM_EF = TypeVar("_CM_EF", AbstractContextManager[Any], _ExitFunc)

class _GeneratorContextManager(AbstractContextManager[_T_co]):
class ContextDecorator:
def __call__(self, func: _F) -> _F: ...

class _GeneratorContextManager(AbstractContextManager[_T_co], ContextDecorator): ...

# type ignore to deal with incomplete ParamSpec support in mypy
def contextmanager(func: Callable[_P, Iterator[_T]]) -> Callable[_P, _GeneratorContextManager[_T]]: ... # type: ignore[misc]

if sys.version_info >= (3, 10):
_AF = TypeVar("_AF", bound=Callable[..., Awaitable[Any]])
class AsyncContextDecorator:
def __call__(self, func: _AF) -> _AF: ...
class _AsyncGeneratorContextManager(AbstractAsyncContextManager[_T_co], AsyncContextDecorator): ...

elif sys.version_info >= (3, 7):
class _AsyncGeneratorContextManager(AbstractAsyncContextManager[_T_co]): ...

if sys.version_info >= (3, 7):
def asynccontextmanager(func: Callable[_P, AsyncIterator[_T]]) -> Callable[_P, AbstractAsyncContextManager[_T]]: ... # type: ignore[misc]
def asynccontextmanager(func: Callable[_P, AsyncIterator[_T]]) -> Callable[_P, _AsyncGeneratorContextManager[_T]]: ... # type: ignore[misc]

class _SupportsClose(Protocol):
def close(self) -> object: ...
Expand All @@ -56,9 +67,6 @@ if sys.version_info >= (3, 10):
_SupportsAcloseT = TypeVar("_SupportsAcloseT", bound=_SupportsAclose)
class aclosing(AbstractAsyncContextManager[_SupportsAcloseT]):
def __init__(self, thing: _SupportsAcloseT) -> None: ...
_AF = TypeVar("_AF", bound=Callable[..., Awaitable[Any]])
class AsyncContextDecorator:
def __call__(self, func: _AF) -> _AF: ...

class suppress(AbstractContextManager[None]):
def __init__(self, *exceptions: Type[BaseException]) -> None: ...
Expand All @@ -72,9 +80,6 @@ class redirect_stdout(AbstractContextManager[_T_io]):
class redirect_stderr(AbstractContextManager[_T_io]):
def __init__(self, new_target: _T_io) -> None: ...

class ContextDecorator:
def __call__(self, func: _F) -> _F: ...

class ExitStack(AbstractContextManager[ExitStack]):
def __init__(self) -> None: ...
def enter_context(self, cm: AbstractContextManager[_T]) -> _T: ...
Expand Down