massive update, probably broken
[dotfiles/.git] / .config / coc / extensions / node_modules / coc-pyright / node_modules / pyright / dist / typeshed-fallback / stdlib / tempfile.pyi
1 import os
2 import sys
3 from _typeshed import Self
4 from types import TracebackType
5 from typing import IO, Any, AnyStr, Generic, Iterable, Iterator, Tuple, Type, Union, overload
6 from typing_extensions import Literal
7
8 if sys.version_info >= (3, 9):
9     from types import GenericAlias
10
11 # global variables
12 TMP_MAX: int
13 tempdir: str | None
14 template: str
15
16 _DirT = Union[AnyStr, os.PathLike[AnyStr]]
17
18 if sys.version_info >= (3, 8):
19     @overload
20     def NamedTemporaryFile(
21         mode: Literal["r", "w", "a", "x", "r+", "w+", "a+", "x+", "rt", "wt", "at", "xt", "r+t", "w+t", "a+t", "x+t"],
22         buffering: int = ...,
23         encoding: str | None = ...,
24         newline: str | None = ...,
25         suffix: AnyStr | None = ...,
26         prefix: AnyStr | None = ...,
27         dir: _DirT[AnyStr] | None = ...,
28         delete: bool = ...,
29         *,
30         errors: str | None = ...,
31     ) -> _TemporaryFileWrapper[str]: ...
32     @overload
33     def NamedTemporaryFile(
34         mode: Literal["rb", "wb", "ab", "xb", "r+b", "w+b", "a+b", "x+b"] = ...,
35         buffering: int = ...,
36         encoding: str | None = ...,
37         newline: str | None = ...,
38         suffix: AnyStr | None = ...,
39         prefix: AnyStr | None = ...,
40         dir: _DirT[AnyStr] | None = ...,
41         delete: bool = ...,
42         *,
43         errors: str | None = ...,
44     ) -> _TemporaryFileWrapper[bytes]: ...
45     @overload
46     def NamedTemporaryFile(
47         mode: str = ...,
48         buffering: int = ...,
49         encoding: str | None = ...,
50         newline: str | None = ...,
51         suffix: AnyStr | None = ...,
52         prefix: AnyStr | None = ...,
53         dir: _DirT[AnyStr] | None = ...,
54         delete: bool = ...,
55         *,
56         errors: str | None = ...,
57     ) -> _TemporaryFileWrapper[Any]: ...
58
59 else:
60     @overload
61     def NamedTemporaryFile(
62         mode: Literal["r", "w", "a", "x", "r+", "w+", "a+", "x+", "rt", "wt", "at", "xt", "r+t", "w+t", "a+t", "x+t"],
63         buffering: int = ...,
64         encoding: str | None = ...,
65         newline: str | None = ...,
66         suffix: AnyStr | None = ...,
67         prefix: AnyStr | None = ...,
68         dir: _DirT[AnyStr] | None = ...,
69         delete: bool = ...,
70     ) -> _TemporaryFileWrapper[str]: ...
71     @overload
72     def NamedTemporaryFile(
73         mode: Literal["rb", "wb", "ab", "xb", "r+b", "w+b", "a+b", "x+b"] = ...,
74         buffering: int = ...,
75         encoding: str | None = ...,
76         newline: str | None = ...,
77         suffix: AnyStr | None = ...,
78         prefix: AnyStr | None = ...,
79         dir: _DirT[AnyStr] | None = ...,
80         delete: bool = ...,
81     ) -> _TemporaryFileWrapper[bytes]: ...
82     @overload
83     def NamedTemporaryFile(
84         mode: str = ...,
85         buffering: int = ...,
86         encoding: str | None = ...,
87         newline: str | None = ...,
88         suffix: AnyStr | None = ...,
89         prefix: AnyStr | None = ...,
90         dir: _DirT[AnyStr] | None = ...,
91         delete: bool = ...,
92     ) -> _TemporaryFileWrapper[Any]: ...
93
94 if sys.platform == "win32":
95     TemporaryFile = NamedTemporaryFile
96 else:
97     if sys.version_info >= (3, 8):
98         @overload
99         def TemporaryFile(
100             mode: Literal["r", "w", "a", "x", "r+", "w+", "a+", "x+", "rt", "wt", "at", "xt", "r+t", "w+t", "a+t", "x+t"],
101             buffering: int = ...,
102             encoding: str | None = ...,
103             newline: str | None = ...,
104             suffix: AnyStr | None = ...,
105             prefix: AnyStr | None = ...,
106             dir: _DirT[AnyStr] | None = ...,
107             *,
108             errors: str | None = ...,
109         ) -> IO[str]: ...
110         @overload
111         def TemporaryFile(
112             mode: Literal["rb", "wb", "ab", "xb", "r+b", "w+b", "a+b", "x+b"] = ...,
113             buffering: int = ...,
114             encoding: str | None = ...,
115             newline: str | None = ...,
116             suffix: AnyStr | None = ...,
117             prefix: AnyStr | None = ...,
118             dir: _DirT[AnyStr] | None = ...,
119             *,
120             errors: str | None = ...,
121         ) -> IO[bytes]: ...
122         @overload
123         def TemporaryFile(
124             mode: str = ...,
125             buffering: int = ...,
126             encoding: str | None = ...,
127             newline: str | None = ...,
128             suffix: AnyStr | None = ...,
129             prefix: AnyStr | None = ...,
130             dir: _DirT[AnyStr] | None = ...,
131             *,
132             errors: str | None = ...,
133         ) -> IO[Any]: ...
134     else:
135         @overload
136         def TemporaryFile(
137             mode: Literal["r", "w", "a", "x", "r+", "w+", "a+", "x+", "rt", "wt", "at", "xt", "r+t", "w+t", "a+t", "x+t"],
138             buffering: int = ...,
139             encoding: str | None = ...,
140             newline: str | None = ...,
141             suffix: AnyStr | None = ...,
142             prefix: AnyStr | None = ...,
143             dir: _DirT[AnyStr] | None = ...,
144         ) -> IO[str]: ...
145         @overload
146         def TemporaryFile(
147             mode: Literal["rb", "wb", "ab", "xb", "r+b", "w+b", "a+b", "x+b"] = ...,
148             buffering: int = ...,
149             encoding: str | None = ...,
150             newline: str | None = ...,
151             suffix: AnyStr | None = ...,
152             prefix: AnyStr | None = ...,
153             dir: _DirT[AnyStr] | None = ...,
154         ) -> IO[bytes]: ...
155         @overload
156         def TemporaryFile(
157             mode: str = ...,
158             buffering: int = ...,
159             encoding: str | None = ...,
160             newline: str | None = ...,
161             suffix: AnyStr | None = ...,
162             prefix: AnyStr | None = ...,
163             dir: _DirT[AnyStr] | None = ...,
164         ) -> IO[Any]: ...
165
166 class _TemporaryFileWrapper(Generic[AnyStr], IO[AnyStr]):
167     file: IO[AnyStr]  # io.TextIOWrapper, io.BufferedReader or io.BufferedWriter
168     name: str
169     delete: bool
170     def __init__(self, file: IO[AnyStr], name: str, delete: bool = ...) -> None: ...
171     def __enter__(self: Self) -> Self: ...
172     def __exit__(self, exc: Type[BaseException] | None, value: BaseException | None, tb: TracebackType | None) -> bool | None: ...
173     def __getattr__(self, name: str) -> Any: ...
174     def close(self) -> None: ...
175     # These methods don't exist directly on this object, but
176     # are delegated to the underlying IO object through __getattr__.
177     # We need to add them here so that this class is concrete.
178     def __iter__(self) -> Iterator[AnyStr]: ...
179     # FIXME: __next__ doesn't actually exist on this class and should be removed:
180     #        see also https://github.com/python/typeshed/pull/5456#discussion_r633068648
181     # >>> import tempfile
182     # >>> ntf=tempfile.NamedTemporaryFile()
183     # >>> next(ntf)
184     # Traceback (most recent call last):
185     #   File "<stdin>", line 1, in <module>
186     # TypeError: '_TemporaryFileWrapper' object is not an iterator
187     def __next__(self) -> AnyStr: ...
188     def fileno(self) -> int: ...
189     def flush(self) -> None: ...
190     def isatty(self) -> bool: ...
191     def read(self, n: int = ...) -> AnyStr: ...
192     def readable(self) -> bool: ...
193     def readline(self, limit: int = ...) -> AnyStr: ...
194     def readlines(self, hint: int = ...) -> list[AnyStr]: ...
195     def seek(self, offset: int, whence: int = ...) -> int: ...
196     def seekable(self) -> bool: ...
197     def tell(self) -> int: ...
198     def truncate(self, size: int | None = ...) -> int: ...
199     def writable(self) -> bool: ...
200     def write(self, s: AnyStr) -> int: ...
201     def writelines(self, lines: Iterable[AnyStr]) -> None: ...
202
203 # It does not actually derive from IO[AnyStr], but it does implement the
204 # protocol.
205 class SpooledTemporaryFile(IO[AnyStr]):
206     @property
207     def encoding(self) -> str: ...  # undocumented
208     @property
209     def newlines(self) -> str | Tuple[str, ...] | None: ...  # undocumented
210     # bytes needs to go first, as default mode is to open as bytes
211     if sys.version_info >= (3, 8):
212         @overload
213         def __init__(
214             self: SpooledTemporaryFile[bytes],
215             max_size: int = ...,
216             mode: Literal["rb", "wb", "ab", "xb", "r+b", "w+b", "a+b", "x+b"] = ...,
217             buffering: int = ...,
218             encoding: str | None = ...,
219             newline: str | None = ...,
220             suffix: str | None = ...,
221             prefix: str | None = ...,
222             dir: str | None = ...,
223             *,
224             errors: str | None = ...,
225         ) -> None: ...
226         @overload
227         def __init__(
228             self: SpooledTemporaryFile[str],
229             max_size: int = ...,
230             mode: Literal["r", "w", "a", "x", "r+", "w+", "a+", "x+", "rt", "wt", "at", "xt", "r+t", "w+t", "a+t", "x+t"] = ...,
231             buffering: int = ...,
232             encoding: str | None = ...,
233             newline: str | None = ...,
234             suffix: str | None = ...,
235             prefix: str | None = ...,
236             dir: str | None = ...,
237             *,
238             errors: str | None = ...,
239         ) -> None: ...
240         @overload
241         def __init__(
242             self,
243             max_size: int = ...,
244             mode: str = ...,
245             buffering: int = ...,
246             encoding: str | None = ...,
247             newline: str | None = ...,
248             suffix: str | None = ...,
249             prefix: str | None = ...,
250             dir: str | None = ...,
251             *,
252             errors: str | None = ...,
253         ) -> None: ...
254         @property
255         def errors(self) -> str | None: ...
256     else:
257         @overload
258         def __init__(
259             self: SpooledTemporaryFile[bytes],
260             max_size: int = ...,
261             mode: Literal["rb", "wb", "ab", "xb", "r+b", "w+b", "a+b", "x+b"] = ...,
262             buffering: int = ...,
263             encoding: str | None = ...,
264             newline: str | None = ...,
265             suffix: str | None = ...,
266             prefix: str | None = ...,
267             dir: str | None = ...,
268         ) -> None: ...
269         @overload
270         def __init__(
271             self: SpooledTemporaryFile[str],
272             max_size: int = ...,
273             mode: Literal["r", "w", "a", "x", "r+", "w+", "a+", "x+", "rt", "wt", "at", "xt", "r+t", "w+t", "a+t", "x+t"] = ...,
274             buffering: int = ...,
275             encoding: str | None = ...,
276             newline: str | None = ...,
277             suffix: str | None = ...,
278             prefix: str | None = ...,
279             dir: str | None = ...,
280         ) -> None: ...
281         @overload
282         def __init__(
283             self,
284             max_size: int = ...,
285             mode: str = ...,
286             buffering: int = ...,
287             encoding: str | None = ...,
288             newline: str | None = ...,
289             suffix: str | None = ...,
290             prefix: str | None = ...,
291             dir: str | None = ...,
292         ) -> None: ...
293     def rollover(self) -> None: ...
294     def __enter__(self: Self) -> Self: ...
295     def __exit__(
296         self, exc_type: Type[BaseException] | None, exc_val: BaseException | None, exc_tb: TracebackType | None
297     ) -> bool | None: ...
298     # These methods are copied from the abstract methods of IO, because
299     # SpooledTemporaryFile implements IO.
300     # See also https://github.com/python/typeshed/pull/2452#issuecomment-420657918.
301     def close(self) -> None: ...
302     def fileno(self) -> int: ...
303     def flush(self) -> None: ...
304     def isatty(self) -> bool: ...
305     def read(self, n: int = ...) -> AnyStr: ...
306     def readline(self, limit: int = ...) -> AnyStr: ...
307     def readlines(self, hint: int = ...) -> list[AnyStr]: ...
308     def seek(self, offset: int, whence: int = ...) -> int: ...
309     def tell(self) -> int: ...
310     def truncate(self, size: int | None = ...) -> int: ...
311     def write(self, s: AnyStr) -> int: ...
312     def writelines(self, iterable: Iterable[AnyStr]) -> None: ...
313     def __iter__(self) -> Iterator[AnyStr]: ...
314     # Other than the following methods, which do not exist on SpooledTemporaryFile
315     def readable(self) -> bool: ...
316     def seekable(self) -> bool: ...
317     def writable(self) -> bool: ...
318     def __next__(self) -> AnyStr: ...
319     if sys.version_info >= (3, 9):
320         def __class_getitem__(cls, item: Any) -> GenericAlias: ...
321
322 class TemporaryDirectory(Generic[AnyStr]):
323     name: AnyStr
324     if sys.version_info >= (3, 10):
325         @overload
326         def __init__(
327             self: TemporaryDirectory[str],
328             suffix: None = ...,
329             prefix: None = ...,
330             dir: None = ...,
331             ignore_cleanup_errors: bool = ...,
332         ) -> None: ...
333         @overload
334         def __init__(
335             self,
336             suffix: AnyStr | None = ...,
337             prefix: AnyStr | None = ...,
338             dir: _DirT[AnyStr] | None = ...,
339             ignore_cleanup_errors: bool = ...,
340         ) -> None: ...
341     else:
342         @overload
343         def __init__(self: TemporaryDirectory[str], suffix: None = ..., prefix: None = ..., dir: None = ...) -> None: ...
344         @overload
345         def __init__(self, suffix: AnyStr | None = ..., prefix: AnyStr | None = ..., dir: _DirT[AnyStr] | None = ...) -> None: ...
346     def cleanup(self) -> None: ...
347     def __enter__(self) -> AnyStr: ...
348     def __exit__(
349         self, exc_type: Type[BaseException] | None, exc_val: BaseException | None, exc_tb: TracebackType | None
350     ) -> None: ...
351     if sys.version_info >= (3, 9):
352         def __class_getitem__(cls, item: Any) -> GenericAlias: ...
353
354 @overload
355 def mkstemp() -> tuple[int, str]: ...
356 @overload
357 def mkstemp(
358     suffix: AnyStr | None = ..., prefix: AnyStr | None = ..., dir: _DirT[AnyStr] | None = ..., text: bool = ...
359 ) -> tuple[int, AnyStr]: ...
360 @overload
361 def mkdtemp() -> str: ...
362 @overload
363 def mkdtemp(suffix: AnyStr | None = ..., prefix: AnyStr | None = ..., dir: _DirT[AnyStr] | None = ...) -> AnyStr: ...
364 @overload
365 def mktemp() -> str: ...
366 @overload
367 def mktemp(suffix: AnyStr | None = ..., prefix: AnyStr | None = ..., dir: _DirT[AnyStr] | None = ...) -> AnyStr: ...
368 def gettempdirb() -> bytes: ...
369 def gettempprefixb() -> bytes: ...
370 def gettempdir() -> str: ...
371 def gettempprefix() -> str: ...