From 8a19fab6b8f92e7b8222e35acb0f5604bf9e91ad Mon Sep 17 00:00:00 2001 From: Hrithik Saini <49943287+hrithiksaini99@users.noreply.github.com> Date: Wed, 4 Nov 2026 13:41:37 +0530 Subject: [PATCH] Allow errors keyword argument in codecs _Encoder, _Decoder, and stream protocols --- stdlib/@tests/test_cases/check_codecs.py | 4 ++++ stdlib/codecs.pyi | 8 ++++---- 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/stdlib/@tests/test_cases/check_codecs.py b/stdlib/@tests/test_cases/check_codecs.py index 19e663ceeaaf..42e871669994 100644 --- a/stdlib/@tests/test_cases/check_codecs.py +++ b/stdlib/@tests/test_cases/check_codecs.py @@ -11,3 +11,7 @@ assert_type(codecs.decode("ab", "hex"), bytes) assert_type(codecs.decode(b"ab", "hex"), bytes) + +info = codecs.lookup("utf-8") +assert_type(info.decode(b"potato", errors="replace"), tuple[str, int]) +assert_type(info.encode("potato", errors="replace"), tuple[bytes, int]) diff --git a/stdlib/codecs.pyi b/stdlib/codecs.pyi index acbf23b5992a..aff0e1a0c9a3 100644 --- a/stdlib/codecs.pyi +++ b/stdlib/codecs.pyi @@ -97,19 +97,19 @@ class _Stream(_WritableStream, _ReadableStream, Protocol): ... @type_check_only class _Encoder(Protocol): - def __call__(self, input: str, errors: str = ..., /) -> tuple[bytes, int]: ... # signature of Codec().encode + def __call__(self, input: str, /, errors: str = ...) -> tuple[bytes, int]: ... # signature of Codec().encode @type_check_only class _Decoder(Protocol): - def __call__(self, input: ReadableBuffer, errors: str = ..., /) -> tuple[str, int]: ... # signature of Codec().decode + def __call__(self, input: ReadableBuffer, /, errors: str = ...) -> tuple[str, int]: ... # signature of Codec().decode @type_check_only class _StreamReader(Protocol): - def __call__(self, stream: _ReadableStream, errors: str = ..., /) -> StreamReader: ... + def __call__(self, stream: _ReadableStream, /, errors: str = ...) -> StreamReader: ... @type_check_only class _StreamWriter(Protocol): - def __call__(self, stream: _WritableStream, errors: str = ..., /) -> StreamWriter: ... + def __call__(self, stream: _WritableStream, /, errors: str = ...) -> StreamWriter: ... @type_check_only class _IncrementalEncoder(Protocol):