add __enter__, __exit__ and __getattr__ to streamreader/writer (#2411)

This commit is contained in:
Martin DeMello
2018-09-04 13:38:18 -07:00
committed by Jelle Zijlstra
parent 8ed0159445
commit 19708fac61

View File

@@ -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)