|
1 | 1 | import _ast
|
2 | 2 | import sys
|
3 | 3 | import types
|
4 |
| -from _typeshed import ( |
5 |
| - OpenBinaryMode, |
6 |
| - OpenBinaryModeReading, |
7 |
| - OpenBinaryModeUpdating, |
8 |
| - OpenBinaryModeWriting, |
9 |
| - OpenTextMode, |
10 |
| - ReadableBuffer, |
11 |
| - StrPath, |
12 |
| -) |
| 4 | +from _typeshed import ReadableBuffer, StrPath |
13 | 5 | from abc import ABCMeta, abstractmethod
|
14 | 6 | from collections.abc import Iterator, Mapping, Sequence
|
15 | 7 | from importlib.machinery import ModuleSpec
|
16 |
| -from io import BufferedRandom, BufferedReader, BufferedWriter, FileIO, TextIOWrapper |
17 |
| -from typing import IO, Any, BinaryIO, Protocol, overload, runtime_checkable |
| 8 | +from io import BufferedReader |
| 9 | +from typing import IO, Any, Protocol, overload, runtime_checkable |
18 | 10 | from typing_extensions import Literal
|
19 | 11 |
|
20 | 12 | if sys.version_info >= (3, 11):
|
@@ -139,75 +131,25 @@ if sys.version_info >= (3, 9):
|
139 | 131 | def joinpath(self, *descendants: str) -> Traversable: ...
|
140 | 132 | else:
|
141 | 133 | @abstractmethod
|
142 |
| - def joinpath(self, child: str) -> Traversable: ... |
143 |
| - # The .open method comes from pathlib.pyi and should be kept in sync. |
144 |
| - @overload |
145 |
| - @abstractmethod |
146 |
| - def open( |
147 |
| - self, |
148 |
| - mode: OpenTextMode = "r", |
149 |
| - buffering: int = ..., |
150 |
| - encoding: str | None = ..., |
151 |
| - errors: str | None = ..., |
152 |
| - newline: str | None = ..., |
153 |
| - ) -> TextIOWrapper: ... |
154 |
| - # Unbuffered binary mode: returns a FileIO |
155 |
| - @overload |
156 |
| - @abstractmethod |
157 |
| - def open( |
158 |
| - self, mode: OpenBinaryMode, buffering: Literal[0], encoding: None = None, errors: None = None, newline: None = None |
159 |
| - ) -> FileIO: ... |
160 |
| - # Buffering is on: return BufferedRandom, BufferedReader, or BufferedWriter |
161 |
| - @overload |
162 |
| - @abstractmethod |
163 |
| - def open( |
164 |
| - self, |
165 |
| - mode: OpenBinaryModeUpdating, |
166 |
| - buffering: Literal[-1, 1] = ..., |
167 |
| - encoding: None = None, |
168 |
| - errors: None = None, |
169 |
| - newline: None = None, |
170 |
| - ) -> BufferedRandom: ... |
171 |
| - @overload |
172 |
| - @abstractmethod |
173 |
| - def open( |
174 |
| - self, |
175 |
| - mode: OpenBinaryModeWriting, |
176 |
| - buffering: Literal[-1, 1] = ..., |
177 |
| - encoding: None = None, |
178 |
| - errors: None = None, |
179 |
| - newline: None = None, |
180 |
| - ) -> BufferedWriter: ... |
181 |
| - @overload |
182 |
| - @abstractmethod |
183 |
| - def open( |
184 |
| - self, |
185 |
| - mode: OpenBinaryModeReading, |
186 |
| - buffering: Literal[-1, 1] = ..., |
187 |
| - encoding: None = None, |
188 |
| - errors: None = None, |
189 |
| - newline: None = None, |
190 |
| - ) -> BufferedReader: ... |
191 |
| - # Buffering cannot be determined: fall back to BinaryIO |
| 134 | + def joinpath(self, __child: str) -> Traversable: ... |
| 135 | + |
| 136 | + # The documentation and runtime protocol allows *args, **kwargs arguments, |
| 137 | + # but this would mean that all implementors would have to support them, |
| 138 | + # which is not the case. |
192 | 139 | @overload
|
193 | 140 | @abstractmethod
|
194 |
| - def open( |
195 |
| - self, mode: OpenBinaryMode, buffering: int = ..., encoding: None = None, errors: None = None, newline: None = None |
196 |
| - ) -> BinaryIO: ... |
197 |
| - # Fallback if mode is not specified |
| 141 | + def open(self, mode: Literal["r", "w"] = "r", *, encoding: str | None = None, errors: str | None = None) -> IO[str]: ... |
198 | 142 | @overload
|
199 | 143 | @abstractmethod
|
200 |
| - def open( |
201 |
| - self, mode: str, buffering: int = ..., encoding: str | None = ..., errors: str | None = ..., newline: str | None = ... |
202 |
| - ) -> IO[Any]: ... |
| 144 | + def open(self, mode: Literal["rb", "wb"]) -> IO[bytes]: ... |
203 | 145 | @property
|
204 | 146 | @abstractmethod
|
205 | 147 | def name(self) -> str: ...
|
206 | 148 | if sys.version_info >= (3, 10):
|
207 |
| - def __truediv__(self, child: str) -> Traversable: ... |
| 149 | + def __truediv__(self, __child: str) -> Traversable: ... |
208 | 150 | else:
|
209 | 151 | @abstractmethod
|
210 |
| - def __truediv__(self, child: str) -> Traversable: ... |
| 152 | + def __truediv__(self, __child: str) -> Traversable: ... |
211 | 153 |
|
212 | 154 | @abstractmethod
|
213 | 155 | def read_bytes(self) -> bytes: ...
|
|
0 commit comments