Skip to content

Commit

Permalink
Correct return type of asynccontextmanager in 3.10 (#6634)
Browse files Browse the repository at this point in the history
  • Loading branch information
AlexWaygood authored Dec 20, 2021
1 parent b1b958d commit 2173c44
Showing 1 changed file with 13 additions and 8 deletions.
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

0 comments on commit 2173c44

Please sign in to comment.