4 from _typeshed import ReadableBuffer, Self, StrOrBytesPath, WriteableBuffer
6 from types import TracebackType
7 from typing import IO, Any, BinaryIO, Callable, Iterable, Iterator, TextIO, Tuple, Type
9 DEFAULT_BUFFER_SIZE: int
17 if sys.version_info >= (3, 8):
18 def open_code(path: str) -> IO[bytes]: ...
20 BlockingIOError = builtins.BlockingIOError
22 class UnsupportedOperation(OSError, ValueError): ...
25 def __iter__(self) -> Iterator[bytes]: ...
26 def __next__(self) -> bytes: ...
27 def __enter__(self: Self) -> Self: ...
29 self, exc_type: Type[BaseException] | None, exc_val: BaseException | None, exc_tb: TracebackType | None
31 def close(self) -> None: ...
32 def fileno(self) -> int: ...
33 def flush(self) -> None: ...
34 def isatty(self) -> bool: ...
35 def readable(self) -> bool: ...
36 read: Callable[..., Any]
37 def readlines(self, __hint: int = ...) -> list[bytes]: ...
38 def seek(self, __offset: int, __whence: int = ...) -> int: ...
39 def seekable(self) -> bool: ...
40 def tell(self) -> int: ...
41 def truncate(self, __size: int | None = ...) -> int: ...
42 def writable(self) -> bool: ...
43 write: Callable[..., Any]
44 def writelines(self, __lines: Iterable[ReadableBuffer]) -> None: ...
45 def readline(self, __size: int | None = ...) -> bytes: ...
46 def __del__(self) -> None: ...
48 def closed(self) -> bool: ...
49 def _checkClosed(self, msg: str | None = ...) -> None: ... # undocumented
51 class RawIOBase(IOBase):
52 def readall(self) -> bytes: ...
53 def readinto(self, __buffer: WriteableBuffer) -> int | None: ...
54 def write(self, __b: ReadableBuffer) -> int | None: ...
55 def read(self, __size: int = ...) -> bytes | None: ...
57 class BufferedIOBase(IOBase):
58 raw: RawIOBase # This is not part of the BufferedIOBase API and may not exist on some implementations.
59 def detach(self) -> RawIOBase: ...
60 def readinto(self, __buffer: WriteableBuffer) -> int: ...
61 def write(self, __buffer: ReadableBuffer) -> int: ...
62 def readinto1(self, __buffer: WriteableBuffer) -> int: ...
63 def read(self, __size: int | None = ...) -> bytes: ...
64 def read1(self, __size: int = ...) -> bytes: ...
66 class FileIO(RawIOBase, BinaryIO):
68 name: StrOrBytesPath | int # type: ignore
70 self, file: StrOrBytesPath | int, mode: str = ..., closefd: bool = ..., opener: _Opener | None = ...
73 def closefd(self) -> bool: ...
74 def write(self, __b: ReadableBuffer) -> int: ...
75 def read(self, __size: int = ...) -> bytes: ...
76 def __enter__(self: Self) -> Self: ...
78 class BytesIO(BufferedIOBase, BinaryIO):
79 def __init__(self, initial_bytes: bytes = ...) -> None: ...
80 # BytesIO does not contain a "name" field. This workaround is necessary
81 # to allow BytesIO sub-classes to add this field, as it is defined
82 # as a read-only property on IO[].
84 def __enter__(self: Self) -> Self: ...
85 def getvalue(self) -> bytes: ...
86 def getbuffer(self) -> memoryview: ...
87 if sys.version_info >= (3, 7):
88 def read1(self, __size: int | None = ...) -> bytes: ...
90 def read1(self, __size: int | None) -> bytes: ... # type: ignore
92 class BufferedReader(BufferedIOBase, BinaryIO):
93 def __enter__(self: Self) -> Self: ...
94 def __init__(self, raw: RawIOBase, buffer_size: int = ...) -> None: ...
95 def peek(self, __size: int = ...) -> bytes: ...
96 if sys.version_info >= (3, 7):
97 def read1(self, __size: int = ...) -> bytes: ...
99 def read1(self, __size: int) -> bytes: ... # type: ignore
101 class BufferedWriter(BufferedIOBase, BinaryIO):
102 def __enter__(self: Self) -> Self: ...
103 def __init__(self, raw: RawIOBase, buffer_size: int = ...) -> None: ...
104 def write(self, __buffer: ReadableBuffer) -> int: ...
106 class BufferedRandom(BufferedReader, BufferedWriter):
107 def __enter__(self: Self) -> Self: ...
108 def __init__(self, raw: RawIOBase, buffer_size: int = ...) -> None: ...
109 def seek(self, __target: int, __whence: int = ...) -> int: ...
110 if sys.version_info >= (3, 7):
111 def read1(self, __size: int = ...) -> bytes: ...
113 def read1(self, __size: int) -> bytes: ... # type: ignore
115 class BufferedRWPair(BufferedIOBase):
116 def __init__(self, reader: RawIOBase, writer: RawIOBase, buffer_size: int = ...) -> None: ...
117 def peek(self, __size: int = ...) -> bytes: ...
119 class TextIOBase(IOBase):
122 newlines: str | Tuple[str, ...] | None
123 def __iter__(self) -> Iterator[str]: ... # type: ignore
124 def __next__(self) -> str: ... # type: ignore
125 def detach(self) -> BinaryIO: ...
126 def write(self, __s: str) -> int: ...
127 def writelines(self, __lines: Iterable[str]) -> None: ... # type: ignore
128 def readline(self, __size: int = ...) -> str: ... # type: ignore
129 def readlines(self, __hint: int = ...) -> list[str]: ... # type: ignore
130 def read(self, __size: int | None = ...) -> str: ...
131 def tell(self) -> int: ...
133 class TextIOWrapper(TextIOBase, TextIO):
137 encoding: str | None = ...,
138 errors: str | None = ...,
139 newline: str | None = ...,
140 line_buffering: bool = ...,
141 write_through: bool = ...,
144 def buffer(self) -> BinaryIO: ...
146 def closed(self) -> bool: ...
148 def line_buffering(self) -> bool: ...
149 if sys.version_info >= (3, 7):
151 def write_through(self) -> bool: ...
155 encoding: str | None = ...,
156 errors: str | None = ...,
157 newline: str | None = ...,
158 line_buffering: bool | None = ...,
159 write_through: bool | None = ...,
161 # These are inherited from TextIOBase, but must exist in the stub to satisfy mypy.
162 def __enter__(self: Self) -> Self: ...
163 def __iter__(self) -> Iterator[str]: ... # type: ignore
164 def __next__(self) -> str: ... # type: ignore
165 def writelines(self, __lines: Iterable[str]) -> None: ... # type: ignore
166 def readline(self, __size: int = ...) -> str: ... # type: ignore
167 def readlines(self, __hint: int = ...) -> list[str]: ... # type: ignore
168 def seek(self, __cookie: int, __whence: int = ...) -> int: ...
170 class StringIO(TextIOWrapper):
171 def __init__(self, initial_value: str | None = ..., newline: str | None = ...) -> None: ...
172 # StringIO does not contain a "name" field. This workaround is necessary
173 # to allow StringIO sub-classes to add this field, as it is defined
174 # as a read-only property on IO[].
176 def getvalue(self) -> str: ...
178 class IncrementalNewlineDecoder(codecs.IncrementalDecoder):
179 def __init__(self, decoder: codecs.IncrementalDecoder | None, translate: bool, errors: str = ...) -> None: ...
180 def decode(self, input: bytes | str, final: bool = ...) -> str: ...
182 def newlines(self) -> str | Tuple[str, ...] | None: ...