Skip to content

Commit ed04d33

Browse files
authored
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 #4283.
1 parent 0704214 commit ed04d33

File tree

1 file changed

+5
-4
lines changed

1 file changed

+5
-4
lines changed

stdlib/2and3/contextlib.pyi

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ if sys.version_info >= (3, 7):
1616
from typing import AsyncContextManager as AbstractAsyncContextManager
1717

1818
_T = TypeVar('_T')
19+
_T_io = TypeVar('_T_io', bound=Optional[IO[str]])
1920
_F = TypeVar('_F', bound=Callable[..., Any])
2021

2122
_ExitFunc = Callable[[Optional[Type[BaseException]],
@@ -48,12 +49,12 @@ if sys.version_info >= (3, 4):
4849
excinst: Optional[BaseException],
4950
exctb: Optional[TracebackType]) -> bool: ...
5051

51-
class redirect_stdout(ContextManager[None]):
52-
def __init__(self, new_target: Optional[IO[str]]) -> None: ...
52+
class redirect_stdout(ContextManager[_T_io]):
53+
def __init__(self, new_target: _T_io) -> None: ...
5354

5455
if sys.version_info >= (3, 5):
55-
class redirect_stderr(ContextManager[None]):
56-
def __init__(self, new_target: Optional[IO[str]]) -> None: ...
56+
class redirect_stderr(ContextManager[_T_io]):
57+
def __init__(self, new_target: _T_io) -> None: ...
5758

5859
if sys.version_info >= (3,):
5960
class ContextDecorator:

0 commit comments

Comments
 (0)