Debian Codegraph @

jedi/third_party/typeshed/stdlib/fileinput.pyi

raw symbols SCIP
1 import sys
2 from _typeshed import AnyStr_co, StrOrBytesPath
3 from collections.abc import Callable, Iterable
4 from types import GenericAlias, TracebackType
5 from typing import IO, Any, AnyStr, Generic, Literal, Protocol, overload, type_check_only
6 from typing_extensions import Self, TypeAlias, deprecated
7
8 __all__ = [
9 "input",
10 "close",
11 "nextfile",
12 "filename",
13 "lineno",
14 "filelineno",
15 "fileno",
16 "isfirstline",
17 "isstdin",
18 "FileInput",
19 "hook_compressed",
20 "hook_encoded",
21 ]
22
23 if sys.version_info >= (3, 11):
24 _TextMode: TypeAlias = Literal["r"]
25 else:
26 _TextMode: TypeAlias = Literal["r", "rU", "U"]
27
28 @type_check_only
29 class _HasReadlineAndFileno(Protocol[AnyStr_co]):
30 def readline(self) -> AnyStr_co: ...
31 def fileno(self) -> int: ...
32
33 if sys.version_info >= (3, 10):
34 # encoding and errors are added
35 @overload
36 def input(
37 files: StrOrBytesPath | Iterable[StrOrBytesPath] | None = None,
38 inplace: bool = False,
39 backup: str = "",
40 *,
41 mode: _TextMode = "r",
42 openhook: Callable[[StrOrBytesPath, str], _HasReadlineAndFileno[str]] | None = None,
43 encoding: str | None = None,
44 errors: str | None = None,
45 ) -> FileInput[str]: ...
46 @overload
47 def input(
48 files: StrOrBytesPath | Iterable[StrOrBytesPath] | None = None,
49 inplace: bool = False,
50 backup: str = "",
51 *,
52 mode: Literal["rb"],
53 openhook: Callable[[StrOrBytesPath, str], _HasReadlineAndFileno[bytes]] | None = None,
54 encoding: None = None,
55 errors: None = None,
56 ) -> FileInput[bytes]: ...
57 @overload
58 def input(
59 files: StrOrBytesPath | Iterable[StrOrBytesPath] | None = None,
60 inplace: bool = False,
61 backup: str = "",
62 *,
63 mode: str,
64 openhook: Callable[[StrOrBytesPath, str], _HasReadlineAndFileno[Any]] | None = None,
65 encoding: str | None = None,
66 errors: str | None = None,
67 ) -> FileInput[Any]: ...
68
69 else:
70 # bufsize is dropped and mode and openhook become keyword-only
71 @overload
72 def input(
73 files: StrOrBytesPath | Iterable[StrOrBytesPath] | None = None,
74 inplace: bool = False,
75 backup: str = "",
76 *,
77 mode: _TextMode = "r",
78 openhook: Callable[[StrOrBytesPath, str], _HasReadlineAndFileno[str]] | None = None,
79 ) -> FileInput[str]: ...
80 @overload
81 def input(
82 files: StrOrBytesPath | Iterable[StrOrBytesPath] | None = None,
83 inplace: bool = False,
84 backup: str = "",
85 *,
86 mode: Literal["rb"],
87 openhook: Callable[[StrOrBytesPath, str], _HasReadlineAndFileno[bytes]] | None = None,
88 ) -> FileInput[bytes]: ...
89 @overload
90 def input(
91 files: StrOrBytesPath | Iterable[StrOrBytesPath] | None = None,
92 inplace: bool = False,
93 backup: str = "",
94 *,
95 mode: str,
96 openhook: Callable[[StrOrBytesPath, str], _HasReadlineAndFileno[Any]] | None = None,
97 ) -> FileInput[Any]: ...
98
99 def close() -> None: ...
100 def nextfile() -> None: ...
101 def filename() -> str: ...
102 def lineno() -> int: ...
103 def filelineno() -> int: ...
104 def fileno() -> int: ...
105 def isfirstline() -> bool: ...
106 def isstdin() -> bool: ...
107
108 class FileInput(Generic[AnyStr]):
109 if sys.version_info >= (3, 10):
110 # encoding and errors are added
111 @overload
112 def __init__(
113 self: FileInput[str],
114 files: StrOrBytesPath | Iterable[StrOrBytesPath] | None = None,
115 inplace: bool = False,
116 backup: str = "",
117 *,
118 mode: _TextMode = "r",
119 openhook: Callable[[StrOrBytesPath, str], _HasReadlineAndFileno[str]] | None = None,
120 encoding: str | None = None,
121 errors: str | None = None,
122 ) -> None: ...
123 @overload
124 def __init__(
125 self: FileInput[bytes],
126 files: StrOrBytesPath | Iterable[StrOrBytesPath] | None = None,
127 inplace: bool = False,
128 backup: str = "",
129 *,
130 mode: Literal["rb"],
131 openhook: Callable[[StrOrBytesPath, str], _HasReadlineAndFileno[bytes]] | None = None,
132 encoding: None = None,
133 errors: None = None,
134 ) -> None: ...
135 @overload
136 def __init__(
137 self: FileInput[Any],
138 files: StrOrBytesPath | Iterable[StrOrBytesPath] | None = None,
139 inplace: bool = False,
140 backup: str = "",
141 *,
142 mode: str,
143 openhook: Callable[[StrOrBytesPath, str], _HasReadlineAndFileno[Any]] | None = None,
144 encoding: str | None = None,
145 errors: str | None = None,
146 ) -> None: ...
147
148 else:
149 # bufsize is dropped and mode and openhook become keyword-only
150 @overload
151 def __init__(
152 self: FileInput[str],
153 files: StrOrBytesPath | Iterable[StrOrBytesPath] | None = None,
154 inplace: bool = False,
155 backup: str = "",
156 *,
157 mode: _TextMode = "r",
158 openhook: Callable[[StrOrBytesPath, str], _HasReadlineAndFileno[str]] | None = None,
159 ) -> None: ...
160 @overload
161 def __init__(
162 self: FileInput[bytes],
163 files: StrOrBytesPath | Iterable[StrOrBytesPath] | None = None,
164 inplace: bool = False,
165 backup: str = "",
166 *,
167 mode: Literal["rb"],
168 openhook: Callable[[StrOrBytesPath, str], _HasReadlineAndFileno[bytes]] | None = None,
169 ) -> None: ...
170 @overload
171 def __init__(
172 self: FileInput[Any],
173 files: StrOrBytesPath | Iterable[StrOrBytesPath] | None = None,
174 inplace: bool = False,
175 backup: str = "",
176 *,
177 mode: str,
178 openhook: Callable[[StrOrBytesPath, str], _HasReadlineAndFileno[Any]] | None = None,
179 ) -> None: ...
180
181 def __del__(self) -> None: ...
182 def close(self) -> None: ...
183 def __enter__(self) -> Self: ...
184 def __exit__(
185 self, type: type[BaseException] | None, value: BaseException | None, traceback: TracebackType | None
186 ) -> None: ...
187 def __iter__(self) -> Self: ...
188 def __next__(self) -> AnyStr: ...
189 if sys.version_info < (3, 11):
190 def __getitem__(self, i: int) -> AnyStr: ...
191
192 def nextfile(self) -> None: ...
193 def readline(self) -> AnyStr: ...
194 def filename(self) -> str: ...
195 def lineno(self) -> int: ...
196 def filelineno(self) -> int: ...
197 def fileno(self) -> int: ...
198 def isfirstline(self) -> bool: ...
199 def isstdin(self) -> bool: ...
200 def __class_getitem__(cls, item: Any, /) -> GenericAlias: ...
201
202 if sys.version_info >= (3, 10):
203 def hook_compressed(
204 filename: StrOrBytesPath, mode: str, *, encoding: str | None = None, errors: str | None = None
205 ) -> IO[Any]: ...
206
207 else:
208 def hook_compressed(filename: StrOrBytesPath, mode: str) -> IO[Any]: ...
209
210 if sys.version_info >= (3, 10):
211 @deprecated("Deprecated since Python 3.10. Use `fileinput.input` or `fileinput.FileInput` instead.")
212 def hook_encoded(encoding: str, errors: str | None = None) -> Callable[[StrOrBytesPath, str], IO[Any]]: ...
213
214 else:
215 def hook_encoded(encoding: str, errors: str | None = None) -> Callable[[StrOrBytesPath, str], IO[Any]]: ...