From 19708fac61364844ae387a4a7ebef24e50d25fb8 Mon Sep 17 00:00:00 2001 From: Martin DeMello Date: Tue, 4 Sep 2018 13:38:18 -0700 Subject: [PATCH] add __enter__, __exit__ and __getattr__ to streamreader/writer (#2411) --- stdlib/2and3/codecs.pyi | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/stdlib/2and3/codecs.pyi b/stdlib/2and3/codecs.pyi index 332c15499..3a28a2958 100644 --- a/stdlib/2and3/codecs.pyi +++ b/stdlib/2and3/codecs.pyi @@ -127,6 +127,8 @@ class BufferedIncrementalDecoder(IncrementalDecoder): def _buffer_decode(self, input: _Encoded, errors: str, final: bool) -> Tuple[_Decoded, int]: ... def decode(self, object: _Encoded, final: bool = ...) -> _Decoded: ... +_SW = TypeVar("_SW", bound=StreamWriter) + # TODO: it is not possible to specify the requirement that all other # attributes and methods are passed-through from the stream. class StreamWriter(Codec): @@ -135,6 +137,13 @@ class StreamWriter(Codec): def write(self, obj: _Decoded) -> None: ... def writelines(self, list: Iterable[_Decoded]) -> None: ... def reset(self) -> None: ... + def __enter__(self: _SW) -> _SW: ... + def __exit__( + self, typ: Optional[Type[BaseException]], exc: Optional[BaseException], tb: Optional[types.TracebackType] + ) -> None: ... + def __getattr__(self, name: str) -> Any: ... + +_SR = TypeVar("_SR", bound=StreamReader) class StreamReader(Codec): errors: str @@ -143,6 +152,11 @@ class StreamReader(Codec): def readline(self, size: int = ..., keepends: bool = ...) -> _Decoded: ... def readlines(self, sizehint: int = ..., keepends: bool = ...) -> List[_Decoded]: ... def reset(self) -> None: ... + def __enter__(self: _SR) -> _SR: ... + def __exit__( + self, typ: Optional[Type[BaseException]], exc: Optional[BaseException], tb: Optional[types.TracebackType] + ) -> None: ... + def __getattr__(self, name: str) -> Any: ... _T = TypeVar("_T", bound=StreamReaderWriter)