Skip to content
This repository has been archived by the owner on Dec 27, 2021. It is now read-only.

Commit

Permalink
Make _GeneratorContextManager covariant (python#4733)
Browse files Browse the repository at this point in the history
  • Loading branch information
JelleZijlstra authored Oct 31, 2020
1 parent c58a93b commit 301325b
Showing 1 changed file with 4 additions and 3 deletions.
7 changes: 4 additions & 3 deletions stdlib/2and3/contextlib.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -11,19 +11,20 @@ if sys.version_info >= (3, 7):
AbstractAsyncContextManager = AsyncContextManager

_T = TypeVar("_T")
_T_co = TypeVar("_T_co", covariant=True)
_T_io = TypeVar("_T_io", bound=Optional[IO[str]])
_F = TypeVar("_F", bound=Callable[..., Any])

_ExitFunc = Callable[[Optional[Type[BaseException]], Optional[BaseException], Optional[TracebackType]], bool]
_CM_EF = TypeVar("_CM_EF", ContextManager[Any], _ExitFunc)

if sys.version_info >= (3, 2):
class _GeneratorContextManager(ContextManager[_T], Generic[_T]):
class _GeneratorContextManager(ContextManager[_T_co]):
def __call__(self, func: _F) -> _F: ...
def contextmanager(func: Callable[..., Iterator[_T]]) -> Callable[..., _GeneratorContextManager[_T]]: ...

else:
class GeneratorContextManager(ContextManager[_T], Generic[_T]):
class GeneratorContextManager(ContextManager[_T_co]):
def __call__(self, func: _F) -> _F: ...
def contextmanager(func: Callable[..., Iterator[_T]]) -> Callable[..., ContextManager[_T]]: ...

Expand All @@ -33,7 +34,7 @@ if sys.version_info >= (3, 7):
if sys.version_info < (3,):
def nested(*mgr: ContextManager[Any]) -> ContextManager[Iterable[Any]]: ...

class closing(ContextManager[_T], Generic[_T]):
class closing(ContextManager[_T]):
def __init__(self, thing: _T) -> None: ...

if sys.version_info >= (3, 4):
Expand Down

0 comments on commit 301325b

Please sign in to comment.