From d294696823be57584dec5dd303a061d3a3f58ddb Mon Sep 17 00:00:00 2001 From: Amethyst Reese Date: Thu, 8 Sep 2022 22:16:48 -0700 Subject: [PATCH 1/4] Add missing attributes for docutils.io `error_string` and `ErrorOutput` were added in `v0.19`. Fills out some missing pieces of `Input` and `FileInput` as well. --- stubs/docutils/docutils/io.pyi | 21 ++++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-) diff --git a/stubs/docutils/docutils/io.pyi b/stubs/docutils/docutils/io.pyi index b8d4751e8fc5..8372b8c675e0 100644 --- a/stubs/docutils/docutils/io.pyi +++ b/stubs/docutils/docutils/io.pyi @@ -1,5 +1,5 @@ from _typeshed import OpenBinaryModeReading, OpenBinaryModeWriting, OpenTextModeReading, OpenTextModeWriting -from typing import Any, ClassVar +from typing import Any, AnyStr, ClassVar, Pattern from docutils import TransformSpec @@ -9,11 +9,17 @@ class InputError(IOError): ... class OutputError(IOError): ... def check_encoding(stream: Any, encoding: str) -> bool | None: ... +def error_string(err: str) -> str: ... class Input(TransformSpec): component_type: ClassVar[str] default_source_path: ClassVar[str | None] def read(self) -> Any: ... + def decode(self, data: AnyStr) -> str: ... + coding_slug: ClassVar[Pattern[bytes]] + byte_order_marks: ClassVar[tuple[tuple[bytes, str], ...]] + def determine_encoding_from_data(self, data: AnyStr) -> str: ... + def isatty(self) -> bool: ... def __getattr__(self, name: str) -> Any: ... # incomplete class Output(TransformSpec): @@ -29,6 +35,18 @@ class Output(TransformSpec): def write(self, data: str) -> Any: ... # returns bytes or str def encode(self, data: str) -> Any: ... # returns bytes or str +class ErrorOutput: + def __init__( + self, + destination: Any | None = ..., + encoding: str | None = ..., + encoding_errors: str | None = ..., + decoding_errors: str | None = ..., + ) -> None: ... + def write(self, data: AnyStr) -> None: ... + def close(self) -> None: ... + def isatty(self) -> bool: ... + class FileInput(Input): def __init__( self, @@ -39,6 +57,7 @@ class FileInput(Input): autoclose: bool = ..., mode: OpenTextModeReading | OpenBinaryModeReading = ..., ) -> None: ... + def read(self) -> str: ... def readlines(self) -> list[str]: ... def close(self) -> None: ... From 08156697894bc2acdbf5fb18c2f5b56ce20d9464 Mon Sep 17 00:00:00 2001 From: Amethyst Reese Date: Sat, 10 Sep 2022 17:14:20 -0700 Subject: [PATCH 2/4] Apply suggested changes --- stubs/docutils/docutils/io.pyi | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/stubs/docutils/docutils/io.pyi b/stubs/docutils/docutils/io.pyi index 8372b8c675e0..118f86290d7a 100644 --- a/stubs/docutils/docutils/io.pyi +++ b/stubs/docutils/docutils/io.pyi @@ -1,5 +1,6 @@ -from _typeshed import OpenBinaryModeReading, OpenBinaryModeWriting, OpenTextModeReading, OpenTextModeWriting -from typing import Any, AnyStr, ClassVar, Pattern +from _typeshed import OpenBinaryModeReading, OpenBinaryModeWriting, OpenTextModeReading, OpenTextModeWriting, SupportsWrite +from typing import Any, ClassVar, Pattern +from typing_extensions import Literal from docutils import TransformSpec @@ -9,18 +10,17 @@ class InputError(IOError): ... class OutputError(IOError): ... def check_encoding(stream: Any, encoding: str) -> bool | None: ... -def error_string(err: str) -> str: ... +def error_string(err: BaseException) -> str: ... class Input(TransformSpec): component_type: ClassVar[str] default_source_path: ClassVar[str | None] def read(self) -> Any: ... - def decode(self, data: AnyStr) -> str: ... + def decode(self, data: str | bytes) -> str: ... coding_slug: ClassVar[Pattern[bytes]] byte_order_marks: ClassVar[tuple[tuple[bytes, str], ...]] - def determine_encoding_from_data(self, data: AnyStr) -> str: ... + def determine_encoding_from_data(self, data: str | bytes) -> str: ... def isatty(self) -> bool: ... - def __getattr__(self, name: str) -> Any: ... # incomplete class Output(TransformSpec): component_type: ClassVar[str] @@ -38,12 +38,12 @@ class Output(TransformSpec): class ErrorOutput: def __init__( self, - destination: Any | None = ..., + destination: str | SupportsWrite[str] | SupportsWrite[bytes] | Literal[False] | None = ..., encoding: str | None = ..., - encoding_errors: str | None = ..., - decoding_errors: str | None = ..., + encoding_errors: str = ..., + decoding_errors: str = ..., ) -> None: ... - def write(self, data: AnyStr) -> None: ... + def write(self, data: str | bytes | Exception) -> None: ... def close(self) -> None: ... def isatty(self) -> bool: ... From 9ed6f72dc07652ec23765698a640bfc032099313 Mon Sep 17 00:00:00 2001 From: Amethyst Reese Date: Sat, 10 Sep 2022 17:37:39 -0700 Subject: [PATCH 3/4] Remove allowlist entry --- stubs/docutils/@tests/stubtest_allowlist.txt | 1 - 1 file changed, 1 deletion(-) diff --git a/stubs/docutils/@tests/stubtest_allowlist.txt b/stubs/docutils/@tests/stubtest_allowlist.txt index b080637bb56d..e8229378f968 100644 --- a/stubs/docutils/@tests/stubtest_allowlist.txt +++ b/stubs/docutils/@tests/stubtest_allowlist.txt @@ -4,7 +4,6 @@ docutils.frontend.ConfigParser.read docutils.frontend.OptionParser.__getattr__ docutils.io.FileOutput.__getattr__ docutils.io.FileOutput.__init__ -docutils.io.Input.__getattr__ docutils.io.Input.__init__ docutils.languages.LanguageImporter.__getattr__ docutils.nodes.Element.__getattr__ From 893f24acc043f1d52a04e07a291b6d28414efabc Mon Sep 17 00:00:00 2001 From: Alex Waygood Date: Sun, 11 Sep 2022 14:43:00 +0100 Subject: [PATCH 4/4] Apply suggestions from code review --- stubs/docutils/docutils/io.pyi | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/stubs/docutils/docutils/io.pyi b/stubs/docutils/docutils/io.pyi index 118f86290d7a..38820a62f925 100644 --- a/stubs/docutils/docutils/io.pyi +++ b/stubs/docutils/docutils/io.pyi @@ -1,5 +1,6 @@ from _typeshed import OpenBinaryModeReading, OpenBinaryModeWriting, OpenTextModeReading, OpenTextModeWriting, SupportsWrite -from typing import Any, ClassVar, Pattern +from re import Pattern +from typing import Any, ClassVar from typing_extensions import Literal from docutils import TransformSpec @@ -19,7 +20,7 @@ class Input(TransformSpec): def decode(self, data: str | bytes) -> str: ... coding_slug: ClassVar[Pattern[bytes]] byte_order_marks: ClassVar[tuple[tuple[bytes, str], ...]] - def determine_encoding_from_data(self, data: str | bytes) -> str: ... + def determine_encoding_from_data(self, data: str | bytes) -> str | None: ... def isatty(self) -> bool: ... class Output(TransformSpec):