From 0b6d134795cabe4a1118e74d3636ee1cc3b2d180 Mon Sep 17 00:00:00 2001 From: Aymeric Augustin Date: Sat, 9 Feb 2019 15:06:46 +0100 Subject: [PATCH] Support the errors arg in codecs factory functions. (#2752) --- stdlib/2and3/codecs.pyi | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/stdlib/2and3/codecs.pyi b/stdlib/2and3/codecs.pyi index 35be5a947..b99ce9134 100644 --- a/stdlib/2and3/codecs.pyi +++ b/stdlib/2and3/codecs.pyi @@ -18,11 +18,15 @@ class _Encoder(Protocol): class _Decoder(Protocol): def __call__(self, input: _Encoded, errors: str = ...) -> Tuple[_Decoded, int]: ... # signature of Codec().decode -# TODO: Replace the following Callable definitions with protocol classes as above. -_StreamReader = Callable[[IO[_Encoded]], StreamReader] # signature of StreamReader __init__ -_StreamWriter = Callable[[IO[_Encoded]], StreamWriter] # signature of StreamWriter __init__ -_IncrementalEncoder = Callable[[], IncrementalEncoder] # signature of IncrementalEncoder __init__ -_IncrementalDecoder = Callable[[], IncrementalDecoder] # signature of IncrementalDecoder __init__ +class _StreamReader(Protocol): + def __call__(self, stream: IO[_Encoded], errors: str = ...) -> StreamReader: ... +class _StreamWriter(Protocol): + def __call__(self, stream: IO[_Encoded], errors: str = ...) -> StreamWriter: ... + +class _IncrementalEncoder(Protocol): + def __call__(self, errors: str = ...) -> IncrementalEncoder: ... +class _IncrementalDecoder(Protocol): + def __call__(self, errors: str = ...) -> IncrementalDecoder: ... def encode(obj: _Decoded, encoding: str = ..., errors: str = ...) -> _Encoded: ... def decode(obj: _Encoded, encoding: str = ..., errors: str = ...) -> _Decoded: ...