Debian Codegraph @

jedi/third_party/typeshed/stdlib/configparser.pyi

raw symbols SCIP
1 import sys
2 from _typeshed import BytesPath, GenericPath, MaybeNone, StrOrBytesPath, StrPath, SupportsWrite
3 from collections.abc import Callable, ItemsView, Iterable, Iterator, Mapping, MutableMapping, Sequence
4 from re import Pattern
5 from typing import Any, AnyStr, ClassVar, Final, Literal, TypeVar, overload, type_check_only
6 from typing_extensions import TypeAlias, deprecated
7
8 if sys.version_info >= (3, 14):
9 __all__ = (
10 "NoSectionError",
11 "DuplicateOptionError",
12 "DuplicateSectionError",
13 "NoOptionError",
14 "InterpolationError",
15 "InterpolationDepthError",
16 "InterpolationMissingOptionError",
17 "InterpolationSyntaxError",
18 "ParsingError",
19 "MissingSectionHeaderError",
20 "MultilineContinuationError",
21 "UnnamedSectionDisabledError",
22 "InvalidWriteError",
23 "ConfigParser",
24 "RawConfigParser",
25 "Interpolation",
26 "BasicInterpolation",
27 "ExtendedInterpolation",
28 "SectionProxy",
29 "ConverterMapping",
30 "DEFAULTSECT",
31 "MAX_INTERPOLATION_DEPTH",
32 "UNNAMED_SECTION",
33 )
34 elif sys.version_info >= (3, 13):
35 __all__ = (
36 "NoSectionError",
37 "DuplicateOptionError",
38 "DuplicateSectionError",
39 "NoOptionError",
40 "InterpolationError",
41 "InterpolationDepthError",
42 "InterpolationMissingOptionError",
43 "InterpolationSyntaxError",
44 "ParsingError",
45 "MissingSectionHeaderError",
46 "ConfigParser",
47 "RawConfigParser",
48 "Interpolation",
49 "BasicInterpolation",
50 "ExtendedInterpolation",
51 "SectionProxy",
52 "ConverterMapping",
53 "DEFAULTSECT",
54 "MAX_INTERPOLATION_DEPTH",
55 "UNNAMED_SECTION",
56 "MultilineContinuationError",
57 )
58 elif sys.version_info >= (3, 12):
59 __all__ = (
60 "NoSectionError",
61 "DuplicateOptionError",
62 "DuplicateSectionError",
63 "NoOptionError",
64 "InterpolationError",
65 "InterpolationDepthError",
66 "InterpolationMissingOptionError",
67 "InterpolationSyntaxError",
68 "ParsingError",
69 "MissingSectionHeaderError",
70 "ConfigParser",
71 "RawConfigParser",
72 "Interpolation",
73 "BasicInterpolation",
74 "ExtendedInterpolation",
75 "LegacyInterpolation",
76 "SectionProxy",
77 "ConverterMapping",
78 "DEFAULTSECT",
79 "MAX_INTERPOLATION_DEPTH",
80 )
81 else:
82 __all__ = [
83 "NoSectionError",
84 "DuplicateOptionError",
85 "DuplicateSectionError",
86 "NoOptionError",
87 "InterpolationError",
88 "InterpolationDepthError",
89 "InterpolationMissingOptionError",
90 "InterpolationSyntaxError",
91 "ParsingError",
92 "MissingSectionHeaderError",
93 "ConfigParser",
94 "SafeConfigParser",
95 "RawConfigParser",
96 "Interpolation",
97 "BasicInterpolation",
98 "ExtendedInterpolation",
99 "LegacyInterpolation",
100 "SectionProxy",
101 "ConverterMapping",
102 "DEFAULTSECT",
103 "MAX_INTERPOLATION_DEPTH",
104 ]
105
106 if sys.version_info >= (3, 13):
107 @type_check_only
108 class _UNNAMED_SECTION: ...
109
110 UNNAMED_SECTION: _UNNAMED_SECTION
111
112 _SectionName: TypeAlias = str | _UNNAMED_SECTION
113 # A list of sections can only include an unnamed section if the parser was initialized with
114 # allow_unnamed_section=True. Any prevents users from having to use explicit
115 # type checks if allow_unnamed_section is False (the default).
116 _SectionNameList: TypeAlias = list[Any]
117 else:
118 _SectionName: TypeAlias = str
119 _SectionNameList: TypeAlias = list[str]
120
121 _Section: TypeAlias = Mapping[str, str]
122 _Parser: TypeAlias = MutableMapping[str, _Section]
123 _ConverterCallback: TypeAlias = Callable[[str], Any]
124 _ConvertersMap: TypeAlias = dict[str, _ConverterCallback]
125 _T = TypeVar("_T")
126
127 DEFAULTSECT: Final = "DEFAULT"
128 MAX_INTERPOLATION_DEPTH: Final = 10
129
130 class Interpolation:
131 def before_get(self, parser: _Parser, section: _SectionName, option: str, value: str, defaults: _Section) -> str: ...
132 def before_set(self, parser: _Parser, section: _SectionName, option: str, value: str) -> str: ...
133 def before_read(self, parser: _Parser, section: _SectionName, option: str, value: str) -> str: ...
134 def before_write(self, parser: _Parser, section: _SectionName, option: str, value: str) -> str: ...
135
136 class BasicInterpolation(Interpolation): ...
137 class ExtendedInterpolation(Interpolation): ...
138
139 if sys.version_info < (3, 13):
140 @deprecated(
141 "Deprecated since Python 3.2; removed in Python 3.13. Use `BasicInterpolation` or `ExtendedInterpolation` instead."
142 )
143 class LegacyInterpolation(Interpolation):
144 def before_get(self, parser: _Parser, section: _SectionName, option: str, value: str, vars: _Section) -> str: ...
145
146 class RawConfigParser(_Parser):
147 _SECT_TMPL: ClassVar[str] # undocumented
148 _OPT_TMPL: ClassVar[str] # undocumented
149 _OPT_NV_TMPL: ClassVar[str] # undocumented
150
151 SECTCRE: Pattern[str]
152 OPTCRE: ClassVar[Pattern[str]]
153 OPTCRE_NV: ClassVar[Pattern[str]] # undocumented
154 NONSPACECRE: ClassVar[Pattern[str]] # undocumented
155
156 BOOLEAN_STATES: ClassVar[Mapping[str, bool]] # undocumented
157 default_section: str
158 if sys.version_info >= (3, 13):
159 @overload
160 def __init__(
161 self,
162 defaults: Mapping[str, str | None] | None = None,
163 dict_type: type[Mapping[str, str]] = ...,
164 *,
165 allow_no_value: Literal[True],
166 delimiters: Sequence[str] = ("=", ":"),
167 comment_prefixes: Sequence[str] = ("#", ";"),
168 inline_comment_prefixes: Sequence[str] | None = None,
169 strict: bool = True,
170 empty_lines_in_values: bool = True,
171 default_section: str = "DEFAULT",
172 interpolation: Interpolation | None = ...,
173 converters: _ConvertersMap = ...,
174 allow_unnamed_section: bool = False,
175 ) -> None: ...
176 @overload
177 def __init__(
178 self,
179 defaults: Mapping[str, str | None] | None,
180 dict_type: type[Mapping[str, str]],
181 allow_no_value: Literal[True],
182 *,
183 delimiters: Sequence[str] = ("=", ":"),
184 comment_prefixes: Sequence[str] = ("#", ";"),
185 inline_comment_prefixes: Sequence[str] | None = None,
186 strict: bool = True,
187 empty_lines_in_values: bool = True,
188 default_section: str = "DEFAULT",
189 interpolation: Interpolation | None = ...,
190 converters: _ConvertersMap = ...,
191 allow_unnamed_section: bool = False,
192 ) -> None: ...
193 @overload
194 def __init__(
195 self,
196 defaults: _Section | None = None,
197 dict_type: type[Mapping[str, str]] = ...,
198 allow_no_value: bool = False,
199 *,
200 delimiters: Sequence[str] = ("=", ":"),
201 comment_prefixes: Sequence[str] = ("#", ";"),
202 inline_comment_prefixes: Sequence[str] | None = None,
203 strict: bool = True,
204 empty_lines_in_values: bool = True,
205 default_section: str = "DEFAULT",
206 interpolation: Interpolation | None = ...,
207 converters: _ConvertersMap = ...,
208 allow_unnamed_section: bool = False,
209 ) -> None: ...
210 else:
211 @overload
212 def __init__(
213 self,
214 defaults: Mapping[str, str | None] | None = None,
215 dict_type: type[Mapping[str, str]] = ...,
216 *,
217 allow_no_value: Literal[True],
218 delimiters: Sequence[str] = ("=", ":"),
219 comment_prefixes: Sequence[str] = ("#", ";"),
220 inline_comment_prefixes: Sequence[str] | None = None,
221 strict: bool = True,
222 empty_lines_in_values: bool = True,
223 default_section: str = "DEFAULT",
224 interpolation: Interpolation | None = ...,
225 converters: _ConvertersMap = ...,
226 ) -> None: ...
227 @overload
228 def __init__(
229 self,
230 defaults: Mapping[str, str | None] | None,
231 dict_type: type[Mapping[str, str]],
232 allow_no_value: Literal[True],
233 *,
234 delimiters: Sequence[str] = ("=", ":"),
235 comment_prefixes: Sequence[str] = ("#", ";"),
236 inline_comment_prefixes: Sequence[str] | None = None,
237 strict: bool = True,
238 empty_lines_in_values: bool = True,
239 default_section: str = "DEFAULT",
240 interpolation: Interpolation | None = ...,
241 converters: _ConvertersMap = ...,
242 ) -> None: ...
243 @overload
244 def __init__(
245 self,
246 defaults: _Section | None = None,
247 dict_type: type[Mapping[str, str]] = ...,
248 allow_no_value: bool = False,
249 *,
250 delimiters: Sequence[str] = ("=", ":"),
251 comment_prefixes: Sequence[str] = ("#", ";"),
252 inline_comment_prefixes: Sequence[str] | None = None,
253 strict: bool = True,
254 empty_lines_in_values: bool = True,
255 default_section: str = "DEFAULT",
256 interpolation: Interpolation | None = ...,
257 converters: _ConvertersMap = ...,
258 ) -> None: ...
259
260 def __len__(self) -> int: ...
261 def __getitem__(self, key: _SectionName) -> SectionProxy: ...
262 def __setitem__(self, key: _SectionName, value: _Section) -> None: ...
263 def __delitem__(self, key: _SectionName) -> None: ...
264 def __iter__(self) -> Iterator[str]: ...
265 def __contains__(self, key: object) -> bool: ...
266 def defaults(self) -> _Section: ...
267 def sections(self) -> _SectionNameList: ...
268 def add_section(self, section: _SectionName) -> None: ...
269 def has_section(self, section: _SectionName) -> bool: ...
270 def options(self, section: _SectionName) -> list[str]: ...
271 def has_option(self, section: _SectionName, option: str) -> bool: ...
272 @overload
273 def read(self, filenames: GenericPath[AnyStr], encoding: str | None = None) -> list[AnyStr]: ...
274 @overload
275 def read(self, filenames: Iterable[StrPath], encoding: str | None = None) -> list[str]: ...
276 @overload
277 def read(self, filenames: Iterable[BytesPath], encoding: str | None = None) -> list[bytes]: ...
278 @overload
279 def read(self, filenames: Iterable[StrOrBytesPath], encoding: str | None = None) -> list[str | bytes]: ...
280 def read_file(self, f: Iterable[str], source: str | None = None) -> None: ...
281 def read_string(self, string: str, source: str = "<string>") -> None: ...
282 def read_dict(self, dictionary: Mapping[str, Mapping[str, Any]], source: str = "<dict>") -> None: ...
283 if sys.version_info < (3, 12):
284 @deprecated("Deprecated since Python 3.2; removed in Python 3.12. Use `parser.read_file()` instead.")
285 def readfp(self, fp: Iterable[str], filename: str | None = None) -> None: ...
286 # These get* methods are partially applied (with the same names) in
287 # SectionProxy; the stubs should be kept updated together
288 @overload
289 def getint(self, section: _SectionName, option: str, *, raw: bool = False, vars: _Section | None = None) -> int: ...
290 @overload
291 def getint(
292 self, section: _SectionName, option: str, *, raw: bool = False, vars: _Section | None = None, fallback: _T
293 ) -> int | _T: ...
294 @overload
295 def getfloat(self, section: _SectionName, option: str, *, raw: bool = False, vars: _Section | None = None) -> float: ...
296 @overload
297 def getfloat(
298 self, section: _SectionName, option: str, *, raw: bool = False, vars: _Section | None = None, fallback: _T
299 ) -> float | _T: ...
300 @overload
301 def getboolean(self, section: _SectionName, option: str, *, raw: bool = False, vars: _Section | None = None) -> bool: ...
302 @overload
303 def getboolean(
304 self, section: _SectionName, option: str, *, raw: bool = False, vars: _Section | None = None, fallback: _T
305 ) -> bool | _T: ...
306 def _get_conv(
307 self,
308 section: _SectionName,
309 option: str,
310 conv: Callable[[str], _T],
311 *,
312 raw: bool = False,
313 vars: _Section | None = None,
314 fallback: _T = ...,
315 ) -> _T: ...
316 # This is incompatible with MutableMapping so we ignore the type
317 @overload # type: ignore[override]
318 def get(self, section: _SectionName, option: str, *, raw: bool = False, vars: _Section | None = None) -> str | MaybeNone: ...
319 @overload
320 def get(
321 self, section: _SectionName, option: str, *, raw: bool = False, vars: _Section | None = None, fallback: _T
322 ) -> str | _T | MaybeNone: ...
323 @overload
324 def items(self, *, raw: bool = False, vars: _Section | None = None) -> ItemsView[str, SectionProxy]: ...
325 @overload
326 def items(self, section: _SectionName, raw: bool = False, vars: _Section | None = None) -> list[tuple[str, str]]: ...
327 def set(self, section: _SectionName, option: str, value: str | None = None) -> None: ...
328 def write(self, fp: SupportsWrite[str], space_around_delimiters: bool = True) -> None: ...
329 def remove_option(self, section: _SectionName, option: str) -> bool: ...
330 def remove_section(self, section: _SectionName) -> bool: ...
331 def optionxform(self, optionstr: str) -> str: ...
332 @property
333 def converters(self) -> ConverterMapping: ...
334
335 class ConfigParser(RawConfigParser):
336 # This is incompatible with MutableMapping so we ignore the type
337 @overload # type: ignore[override]
338 def get(self, section: _SectionName, option: str, *, raw: bool = False, vars: _Section | None = None) -> str: ...
339 @overload
340 def get(
341 self, section: _SectionName, option: str, *, raw: bool = False, vars: _Section | None = None, fallback: _T
342 ) -> str | _T: ...
343
344 if sys.version_info < (3, 12):
345 @deprecated("Deprecated since Python 3.2; removed in Python 3.12. Use `ConfigParser` instead.")
346 class SafeConfigParser(ConfigParser): ...
347
348 class SectionProxy(MutableMapping[str, str]):
349 def __init__(self, parser: RawConfigParser, name: str) -> None: ...
350 def __getitem__(self, key: str) -> str: ...
351 def __setitem__(self, key: str, value: str) -> None: ...
352 def __delitem__(self, key: str) -> None: ...
353 def __contains__(self, key: object) -> bool: ...
354 def __len__(self) -> int: ...
355 def __iter__(self) -> Iterator[str]: ...
356 @property
357 def parser(self) -> RawConfigParser: ...
358 @property
359 def name(self) -> str: ...
360 # This is incompatible with MutableMapping so we ignore the type
361 @overload # type: ignore[override]
362 def get(
363 self,
364 option: str,
365 fallback: None = None,
366 *,
367 raw: bool = False,
368 vars: _Section | None = None,
369 _impl: Any | None = None,
370 **kwargs: Any, # passed to the underlying parser's get() method
371 ) -> str | None: ...
372 @overload
373 def get(
374 self,
375 option: str,
376 fallback: _T,
377 *,
378 raw: bool = False,
379 vars: _Section | None = None,
380 _impl: Any | None = None,
381 **kwargs: Any, # passed to the underlying parser's get() method
382 ) -> str | _T: ...
383 # These are partially-applied version of the methods with the same names in
384 # RawConfigParser; the stubs should be kept updated together
385 @overload
386 def getint(self, option: str, *, raw: bool = False, vars: _Section | None = None) -> int | None: ...
387 @overload
388 def getint(self, option: str, fallback: _T = ..., *, raw: bool = False, vars: _Section | None = None) -> int | _T: ...
389 @overload
390 def getfloat(self, option: str, *, raw: bool = False, vars: _Section | None = None) -> float | None: ...
391 @overload
392 def getfloat(self, option: str, fallback: _T = ..., *, raw: bool = False, vars: _Section | None = None) -> float | _T: ...
393 @overload
394 def getboolean(self, option: str, *, raw: bool = False, vars: _Section | None = None) -> bool | None: ...
395 @overload
396 def getboolean(self, option: str, fallback: _T = ..., *, raw: bool = False, vars: _Section | None = None) -> bool | _T: ...
397 # SectionProxy can have arbitrary attributes when custom converters are used
398 def __getattr__(self, key: str) -> Callable[..., Any]: ...
399
400 class ConverterMapping(MutableMapping[str, _ConverterCallback | None]):
401 GETTERCRE: ClassVar[Pattern[Any]]
402 def __init__(self, parser: RawConfigParser) -> None: ...
403 def __getitem__(self, key: str) -> _ConverterCallback: ...
404 def __setitem__(self, key: str, value: _ConverterCallback | None) -> None: ...
405 def __delitem__(self, key: str) -> None: ...
406 def __iter__(self) -> Iterator[str]: ...
407 def __len__(self) -> int: ...
408
409 class Error(Exception):
410 message: str
411 def __init__(self, msg: str = "") -> None: ...
412
413 class NoSectionError(Error):
414 section: _SectionName
415 def __init__(self, section: _SectionName) -> None: ...
416
417 class DuplicateSectionError(Error):
418 section: _SectionName
419 source: str | None
420 lineno: int | None
421 def __init__(self, section: _SectionName, source: str | None = None, lineno: int | None = None) -> None: ...
422
423 class DuplicateOptionError(Error):
424 section: _SectionName
425 option: str
426 source: str | None
427 lineno: int | None
428 def __init__(self, section: _SectionName, option: str, source: str | None = None, lineno: int | None = None) -> None: ...
429
430 class NoOptionError(Error):
431 section: _SectionName
432 option: str
433 def __init__(self, option: str, section: _SectionName) -> None: ...
434
435 class InterpolationError(Error):
436 section: _SectionName
437 option: str
438 def __init__(self, option: str, section: _SectionName, msg: str) -> None: ...
439
440 class InterpolationDepthError(InterpolationError):
441 def __init__(self, option: str, section: _SectionName, rawval: object) -> None: ...
442
443 class InterpolationMissingOptionError(InterpolationError):
444 reference: str
445 def __init__(self, option: str, section: _SectionName, rawval: object, reference: str) -> None: ...
446
447 class InterpolationSyntaxError(InterpolationError): ...
448
449 class ParsingError(Error):
450 source: str
451 errors: list[tuple[int, str]]
452 if sys.version_info >= (3, 13):
453 def __init__(self, source: str, *args: object) -> None: ...
454 def combine(self, others: Iterable[ParsingError]) -> ParsingError: ...
455 elif sys.version_info >= (3, 12):
456 def __init__(self, source: str) -> None: ...
457 else:
458 @overload
459 def __init__(self, source: str) -> None: ...
460 @overload
461 @deprecated("The `filename` parameter removed in Python 3.12. Use `source` instead.")
462 def __init__(self, source: None, filename: str | None) -> None: ...
463 @overload
464 @deprecated("The `filename` parameter removed in Python 3.12. Use `source` instead.")
465 def __init__(self, source: None = None, *, filename: str | None) -> None: ...
466
467 def append(self, lineno: int, line: str) -> None: ...
468
469 if sys.version_info < (3, 12):
470 @property
471 @deprecated("Deprecated since Python 3.2; removed in Python 3.12. Use `source` instead.")
472 def filename(self) -> str: ...
473 @filename.setter
474 @deprecated("Deprecated since Python 3.2; removed in Python 3.12. Use `source` instead.")
475 def filename(self, value: str) -> None: ...
476
477 class MissingSectionHeaderError(ParsingError):
478 lineno: int
479 line: str
480 def __init__(self, filename: str, lineno: int, line: str) -> None: ...
481
482 if sys.version_info >= (3, 13):
483 class MultilineContinuationError(ParsingError):
484 lineno: int
485 line: str
486 def __init__(self, filename: str, lineno: int, line: str) -> None: ...
487
488 if sys.version_info >= (3, 14):
489 class UnnamedSectionDisabledError(Error):
490 msg: Final = "Support for UNNAMED_SECTION is disabled."
491 def __init__(self) -> None: ...
492
493 class InvalidWriteError(Error): ...