2 from _typeshed import StrOrBytesPath, StrPath, SupportsWrite
3 from collections.abc import Callable, ItemsView, Iterable, Iterator, Mapping, MutableMapping, Sequence
4 from typing import Any, ClassVar, Dict, Optional, Pattern, Type, TypeVar, overload
5 from typing_extensions import Literal
7 # Internal type aliases
8 _section = Mapping[str, str]
9 _parser = MutableMapping[str, _section]
10 _converter = Callable[[str], Any]
11 _converters = Dict[str, _converter]
14 if sys.version_info >= (3, 7):
15 _Path = StrOrBytesPath
20 MAX_INTERPOLATION_DEPTH: int
23 def before_get(self, parser: _parser, section: str, option: str, value: str, defaults: _section) -> str: ...
24 def before_set(self, parser: _parser, section: str, option: str, value: str) -> str: ...
25 def before_read(self, parser: _parser, section: str, option: str, value: str) -> str: ...
26 def before_write(self, parser: _parser, section: str, option: str, value: str) -> str: ...
28 class BasicInterpolation(Interpolation): ...
29 class ExtendedInterpolation(Interpolation): ...
31 class LegacyInterpolation(Interpolation):
32 def before_get(self, parser: _parser, section: str, option: str, value: str, vars: _section) -> str: ...
34 class RawConfigParser(_parser):
35 _SECT_TMPL: ClassVar[str] # undocumented
36 _OPT_TMPL: ClassVar[str] # undocumented
37 _OPT_NV_TMPL: ClassVar[str] # undocumented
40 OPTCRE: ClassVar[Pattern[str]]
41 OPTCRE_NV: ClassVar[Pattern[str]] # undocumented
42 NONSPACECRE: ClassVar[Pattern[str]] # undocumented
44 BOOLEAN_STATES: ClassVar[Mapping[str, bool]] # undocumented
49 defaults: Mapping[str, str | None] | None = ...,
50 dict_type: Type[Mapping[str, str]] = ...,
51 allow_no_value: Literal[True] = ...,
53 delimiters: Sequence[str] = ...,
54 comment_prefixes: Sequence[str] = ...,
55 inline_comment_prefixes: Sequence[str] | None = ...,
57 empty_lines_in_values: bool = ...,
58 default_section: str = ...,
59 interpolation: Interpolation | None = ...,
60 converters: _converters = ...,
65 defaults: _section | None = ...,
66 dict_type: Type[Mapping[str, str]] = ...,
67 allow_no_value: bool = ...,
69 delimiters: Sequence[str] = ...,
70 comment_prefixes: Sequence[str] = ...,
71 inline_comment_prefixes: Sequence[str] | None = ...,
73 empty_lines_in_values: bool = ...,
74 default_section: str = ...,
75 interpolation: Interpolation | None = ...,
76 converters: _converters = ...,
78 def __len__(self) -> int: ...
79 def __getitem__(self, section: str) -> SectionProxy: ...
80 def __setitem__(self, section: str, options: _section) -> None: ...
81 def __delitem__(self, section: str) -> None: ...
82 def __iter__(self) -> Iterator[str]: ...
83 def defaults(self) -> _section: ...
84 def sections(self) -> list[str]: ...
85 def add_section(self, section: str) -> None: ...
86 def has_section(self, section: str) -> bool: ...
87 def options(self, section: str) -> list[str]: ...
88 def has_option(self, section: str, option: str) -> bool: ...
89 def read(self, filenames: _Path | Iterable[_Path], encoding: str | None = ...) -> list[str]: ...
90 def read_file(self, f: Iterable[str], source: str | None = ...) -> None: ...
91 def read_string(self, string: str, source: str = ...) -> None: ...
92 def read_dict(self, dictionary: Mapping[str, Mapping[str, Any]], source: str = ...) -> None: ...
93 def readfp(self, fp: Iterable[str], filename: str | None = ...) -> None: ...
94 # These get* methods are partially applied (with the same names) in
95 # SectionProxy; the stubs should be kept updated together
97 def getint(self, section: str, option: str, *, raw: bool = ..., vars: _section | None = ...) -> int: ...
100 self, section: str, option: str, *, raw: bool = ..., vars: _section | None = ..., fallback: _T = ...
103 def getfloat(self, section: str, option: str, *, raw: bool = ..., vars: _section | None = ...) -> float: ...
106 self, section: str, option: str, *, raw: bool = ..., vars: _section | None = ..., fallback: _T = ...
109 def getboolean(self, section: str, option: str, *, raw: bool = ..., vars: _section | None = ...) -> bool: ...
112 self, section: str, option: str, *, raw: bool = ..., vars: _section | None = ..., fallback: _T = ...
118 conv: Callable[[str], _T],
121 vars: _section | None = ...,
124 # This is incompatible with MutableMapping so we ignore the type
125 @overload # type: ignore
126 def get(self, section: str, option: str, *, raw: bool = ..., vars: _section | None = ...) -> str: ...
128 def get(self, section: str, option: str, *, raw: bool = ..., vars: _section | None = ..., fallback: _T) -> str | _T: ...
130 def items(self, *, raw: bool = ..., vars: _section | None = ...) -> ItemsView[str, SectionProxy]: ...
132 def items(self, section: str, raw: bool = ..., vars: _section | None = ...) -> list[tuple[str, str]]: ...
133 def set(self, section: str, option: str, value: str | None = ...) -> None: ...
134 def write(self, fp: SupportsWrite[str], space_around_delimiters: bool = ...) -> None: ...
135 def remove_option(self, section: str, option: str) -> bool: ...
136 def remove_section(self, section: str) -> bool: ...
137 def optionxform(self, optionstr: str) -> str: ...
139 class ConfigParser(RawConfigParser): ...
140 class SafeConfigParser(ConfigParser): ...
142 class SectionProxy(MutableMapping[str, str]):
143 def __init__(self, parser: RawConfigParser, name: str) -> None: ...
144 def __getitem__(self, key: str) -> str: ...
145 def __setitem__(self, key: str, value: str) -> None: ...
146 def __delitem__(self, key: str) -> None: ...
147 def __contains__(self, key: object) -> bool: ...
148 def __len__(self) -> int: ...
149 def __iter__(self) -> Iterator[str]: ...
151 def parser(self) -> RawConfigParser: ...
153 def name(self) -> str: ...
154 def get(self, option: str, fallback: str | None = ..., *, raw: bool = ..., vars: _section | None = ..., _impl: Any | None = ..., **kwargs: Any) -> str: ... # type: ignore
155 # These are partially-applied version of the methods with the same names in
156 # RawConfigParser; the stubs should be kept updated together
158 def getint(self, option: str, *, raw: bool = ..., vars: _section | None = ...) -> int: ...
160 def getint(self, option: str, fallback: _T = ..., *, raw: bool = ..., vars: _section | None = ...) -> int | _T: ...
162 def getfloat(self, option: str, *, raw: bool = ..., vars: _section | None = ...) -> float: ...
164 def getfloat(self, option: str, fallback: _T = ..., *, raw: bool = ..., vars: _section | None = ...) -> float | _T: ...
166 def getboolean(self, option: str, *, raw: bool = ..., vars: _section | None = ...) -> bool: ...
168 def getboolean(self, option: str, fallback: _T = ..., *, raw: bool = ..., vars: _section | None = ...) -> bool | _T: ...
169 # SectionProxy can have arbitrary attributes when custom converters are used
170 def __getattr__(self, key: str) -> Callable[..., Any]: ...
172 class ConverterMapping(MutableMapping[str, Optional[_converter]]):
173 GETTERCRE: Pattern[Any]
174 def __init__(self, parser: RawConfigParser) -> None: ...
175 def __getitem__(self, key: str) -> _converter: ...
176 def __setitem__(self, key: str, value: _converter | None) -> None: ...
177 def __delitem__(self, key: str) -> None: ...
178 def __iter__(self) -> Iterator[str]: ...
179 def __len__(self) -> int: ...
181 class Error(Exception):
183 def __init__(self, msg: str = ...) -> None: ...
185 class NoSectionError(Error):
187 def __init__(self, section: str) -> None: ...
189 class DuplicateSectionError(Error):
193 def __init__(self, section: str, source: str | None = ..., lineno: int | None = ...) -> None: ...
195 class DuplicateOptionError(Error):
200 def __init__(self, section: str, option: str, source: str | None = ..., lineno: int | None = ...) -> None: ...
202 class NoOptionError(Error):
205 def __init__(self, option: str, section: str) -> None: ...
207 class InterpolationError(Error):
210 def __init__(self, option: str, section: str, msg: str) -> None: ...
212 class InterpolationDepthError(InterpolationError):
213 def __init__(self, option: str, section: str, rawval: object) -> None: ...
215 class InterpolationMissingOptionError(InterpolationError):
217 def __init__(self, option: str, section: str, rawval: object, reference: str) -> None: ...
219 class InterpolationSyntaxError(InterpolationError): ...
221 class ParsingError(Error):
223 errors: list[tuple[int, str]]
224 def __init__(self, source: str | None = ..., filename: str | None = ...) -> None: ...
225 def append(self, lineno: int, line: str) -> None: ...
227 class MissingSectionHeaderError(ParsingError):
230 def __init__(self, filename: str, lineno: int, line: str) -> None: ...