From ed04d33defa6d623b2e3132155f7620096401789 Mon Sep 17 00:00:00 2001 From: Peter Law Date: Sun, 28 Jun 2020 15:36:09 +0100 Subject: [PATCH] Make redirect_std{out,err} yield new stream as context var (#4285) This matches the implementation, even though this behaviour isn't actually documented yet. https://bugs.python.org/issue41147 aims to fix the documentation issue though. Fixes https://github.com/python/typeshed/issues/4283. --- stdlib/2and3/contextlib.pyi | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/stdlib/2and3/contextlib.pyi b/stdlib/2and3/contextlib.pyi index f0dec323908a..54586c7e3f09 100644 --- a/stdlib/2and3/contextlib.pyi +++ b/stdlib/2and3/contextlib.pyi @@ -16,6 +16,7 @@ if sys.version_info >= (3, 7): from typing import AsyncContextManager as AbstractAsyncContextManager _T = TypeVar('_T') +_T_io = TypeVar('_T_io', bound=Optional[IO[str]]) _F = TypeVar('_F', bound=Callable[..., Any]) _ExitFunc = Callable[[Optional[Type[BaseException]], @@ -48,12 +49,12 @@ if sys.version_info >= (3, 4): excinst: Optional[BaseException], exctb: Optional[TracebackType]) -> bool: ... - class redirect_stdout(ContextManager[None]): - def __init__(self, new_target: Optional[IO[str]]) -> None: ... + class redirect_stdout(ContextManager[_T_io]): + def __init__(self, new_target: _T_io) -> None: ... if sys.version_info >= (3, 5): - class redirect_stderr(ContextManager[None]): - def __init__(self, new_target: Optional[IO[str]]) -> None: ... + class redirect_stderr(ContextManager[_T_io]): + def __init__(self, new_target: _T_io) -> None: ... if sys.version_info >= (3,): class ContextDecorator: