From 05a2d77c6a9b40409e413fb808e5f9971dc759f6 Mon Sep 17 00:00:00 2001 From: sobolevn Date: Tue, 1 Nov 2022 11:53:21 +0300 Subject: [PATCH 1/3] io: improve bytes handling --- stdlib/io.pyi | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/stdlib/io.pyi b/stdlib/io.pyi index 2d3aadc483f0..758613c7e1fa 100644 --- a/stdlib/io.pyi +++ b/stdlib/io.pyi @@ -190,7 +190,7 @@ class StringIO(TextIOWrapper): class IncrementalNewlineDecoder(codecs.IncrementalDecoder): def __init__(self, decoder: codecs.IncrementalDecoder | None, translate: bool, errors: str = ...) -> None: ... - def decode(self, input: bytes | str, final: bool = ...) -> str: ... + def decode(self, input: ReadableBuffer, final: bool = ...) -> str: ... @property def newlines(self) -> str | tuple[str, ...] | None: ... def setstate(self, __state: tuple[bytes, int]) -> None: ... From f27459fe2412cdf49b8e60cb7f3310cf7c1f40cc Mon Sep 17 00:00:00 2001 From: Nikita Sobolev Date: Wed, 2 Nov 2022 00:37:11 +0300 Subject: [PATCH 2/3] Update io.pyi --- stdlib/io.pyi | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/stdlib/io.pyi b/stdlib/io.pyi index 758613c7e1fa..9c4c769fe34b 100644 --- a/stdlib/io.pyi +++ b/stdlib/io.pyi @@ -190,7 +190,7 @@ class StringIO(TextIOWrapper): class IncrementalNewlineDecoder(codecs.IncrementalDecoder): def __init__(self, decoder: codecs.IncrementalDecoder | None, translate: bool, errors: str = ...) -> None: ... - def decode(self, input: ReadableBuffer, final: bool = ...) -> str: ... + def decode(self, input: ReadableBuffer | str, final: bool = ...) -> str: ... @property def newlines(self) -> str | tuple[str, ...] | None: ... def setstate(self, __state: tuple[bytes, int]) -> None: ... From a674b5559c2fb01b2f7770e5092b9f2a405477da Mon Sep 17 00:00:00 2001 From: sobolevn Date: Wed, 2 Nov 2022 11:03:31 +0300 Subject: [PATCH 3/3] codecs: improve bytes handling --- stdlib/codecs.pyi | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/stdlib/codecs.pyi b/stdlib/codecs.pyi index a7b60e38df11..26c4a5801678 100644 --- a/stdlib/codecs.pyi +++ b/stdlib/codecs.pyi @@ -1,5 +1,5 @@ import types -from _typeshed import Self +from _typeshed import ReadableBuffer, Self from abc import abstractmethod from collections.abc import Callable, Generator, Iterable from typing import Any, BinaryIO, Protocol, TextIO @@ -173,7 +173,7 @@ class IncrementalDecoder: errors: str def __init__(self, errors: str = ...) -> None: ... @abstractmethod - def decode(self, input: bytes, final: bool = ...) -> str: ... + def decode(self, input: ReadableBuffer, final: bool = ...) -> str: ... def reset(self) -> None: ... def getstate(self) -> tuple[bytes, int]: ... def setstate(self, state: tuple[bytes, int]) -> None: ... @@ -190,8 +190,8 @@ class BufferedIncrementalDecoder(IncrementalDecoder): buffer: bytes def __init__(self, errors: str = ...) -> None: ... @abstractmethod - def _buffer_decode(self, input: bytes, errors: str, final: bool) -> tuple[str, int]: ... - def decode(self, input: bytes, final: bool = ...) -> str: ... + def _buffer_decode(self, input: ReadableBuffer, errors: str, final: bool) -> tuple[str, int]: ... + def decode(self, input: ReadableBuffer, final: bool = ...) -> str: ... # TODO: it is not possible to specify the requirement that all other # attributes and methods are passed-through from the stream.