Skip to content

Commit ccd8e05

Browse files
ekanshulclaude
andcommitted
[docutils] Improve types in docutils.io
Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
1 parent e8b9e19 commit ccd8e05

1 file changed

Lines changed: 25 additions & 22 deletions

File tree

stubs/docutils/docutils/io.pyi

Lines changed: 25 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,12 @@ from _typeshed import (
44
OpenBinaryModeWriting,
55
OpenTextModeReading,
66
OpenTextModeWriting,
7+
StrPath,
78
SupportsWrite,
89
Unused,
910
)
1011
from re import Pattern
11-
from typing import IO, Any, ClassVar, Final, Generic, Literal, TextIO, TypeVar
12+
from typing import IO, Any, BinaryIO, ClassVar, Final, Generic, Literal, TextIO, TypeVar
1213
from typing_extensions import deprecated
1314

1415
from docutils import TransformSpec, nodes
@@ -49,21 +50,25 @@ class Input(TransformSpec, Generic[_S]):
4950
class Output(TransformSpec):
5051
component_type: ClassVar[str]
5152
default_destination_path: ClassVar[str | None]
52-
encoding: Incomplete
53-
error_handler: Incomplete
53+
encoding: str | None
54+
error_handler: str
5455
destination: Incomplete
55-
destination_path: Incomplete
56+
destination_path: StrPath | None
5657
def __init__(
57-
self, destination=None, destination_path=None, encoding: str | None = None, error_handler: str = "strict"
58+
self,
59+
destination=None,
60+
destination_path: StrPath | None = None,
61+
encoding: str | None = None,
62+
error_handler: str | None = "strict",
5863
) -> None: ...
5964
def write(self, data: str) -> Any: ... # returns bytes or str
6065
def encode(self, data: str) -> Any: ... # returns bytes or str
6166

6267
class ErrorOutput:
63-
destination: Incomplete
64-
encoding: Incomplete
65-
encoding_errors: Incomplete
66-
decoding_errors: Incomplete
68+
destination: TextIO | BinaryIO | Literal[False]
69+
encoding: str
70+
encoding_errors: str
71+
decoding_errors: str
6772
def __init__(
6873
self,
6974
destination: str | SupportsWrite[str] | SupportsWrite[bytes] | Literal[False] | None = None,
@@ -80,9 +85,9 @@ class FileInput(Input[IO[str]]):
8085
def __init__(
8186
self,
8287
source=None,
83-
source_path=None,
88+
source_path: StrPath | None = None,
8489
encoding: str | None = "utf-8",
85-
error_handler: str = "strict",
90+
error_handler: str | None = "strict",
8691
autoclose: bool = True,
8792
mode: OpenTextModeReading | OpenBinaryModeReading = "r",
8893
) -> None: ...
@@ -94,34 +99,32 @@ class FileOutput(Output):
9499
default_destination_path: ClassVar[str]
95100
mode: ClassVar[OpenTextModeWriting | OpenBinaryModeWriting]
96101
opened: bool
97-
autoclose: Incomplete
98-
destination: Incomplete
99-
destination_path: Incomplete
102+
autoclose: bool
100103
def __init__(
101104
self,
102105
destination=None,
103-
destination_path=None,
104-
encoding=None,
105-
error_handler: str = "strict",
106+
destination_path: StrPath | None = None,
107+
encoding: str | None = None,
108+
error_handler: str | None = "strict",
106109
autoclose: bool = True,
107-
handle_io_errors=None,
108-
mode=None,
110+
handle_io_errors: None = None,
111+
mode: OpenTextModeWriting | OpenBinaryModeWriting | None = None,
109112
) -> None: ...
110113
def open(self) -> None: ...
111-
def write(self, data): ...
114+
def write(self, data: str | bytes) -> str | bytes: ...
112115
def close(self) -> None: ...
113116

114117
@deprecated("The `BinaryFileOutput` is deprecated by `FileOutput` and will be removed in Docutils 0.24.")
115118
class BinaryFileOutput(FileOutput): ...
116119

117120
class StringInput(Input[str]):
118121
default_source_path: ClassVar[str]
119-
def read(self): ...
122+
def read(self) -> str: ...
120123

121124
class StringOutput(Output):
122125
default_destination_path: ClassVar[str]
123126
destination: str | bytes # only defined after call to write()
124-
def write(self, data): ...
127+
def write(self, data: str | bytes) -> str | bytes: ...
125128

126129
class NullInput(Input[Any]):
127130
default_source_path: ClassVar[str]

0 commit comments

Comments
 (0)