Skip to content

Commit abea36c

Browse files
authored
Improve configparser alias names (#8254)
1 parent 96bc17a commit abea36c

File tree

1 file changed

+37
-38
lines changed

1 file changed

+37
-38
lines changed

stdlib/configparser.pyi

Lines changed: 37 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -28,11 +28,10 @@ __all__ = [
2828
"MAX_INTERPOLATION_DEPTH",
2929
]
3030

31-
# Internal type aliases
32-
_section: TypeAlias = Mapping[str, str]
33-
_parser: TypeAlias = MutableMapping[str, _section]
34-
_converter: TypeAlias = Callable[[str], Any]
35-
_converters: TypeAlias = dict[str, _converter]
31+
_Section: TypeAlias = Mapping[str, str]
32+
_Parser: TypeAlias = MutableMapping[str, _Section]
33+
_ConverterCallback: TypeAlias = Callable[[str], Any]
34+
_ConvertersMap: TypeAlias = dict[str, _ConverterCallback]
3635
_T = TypeVar("_T")
3736

3837
if sys.version_info >= (3, 7):
@@ -44,18 +43,18 @@ DEFAULTSECT: Literal["DEFAULT"]
4443
MAX_INTERPOLATION_DEPTH: Literal[10]
4544

4645
class Interpolation:
47-
def before_get(self, parser: _parser, section: str, option: str, value: str, defaults: _section) -> str: ...
48-
def before_set(self, parser: _parser, section: str, option: str, value: str) -> str: ...
49-
def before_read(self, parser: _parser, section: str, option: str, value: str) -> str: ...
50-
def before_write(self, parser: _parser, section: str, option: str, value: str) -> str: ...
46+
def before_get(self, parser: _Parser, section: str, option: str, value: str, defaults: _Section) -> str: ...
47+
def before_set(self, parser: _Parser, section: str, option: str, value: str) -> str: ...
48+
def before_read(self, parser: _Parser, section: str, option: str, value: str) -> str: ...
49+
def before_write(self, parser: _Parser, section: str, option: str, value: str) -> str: ...
5150

5251
class BasicInterpolation(Interpolation): ...
5352
class ExtendedInterpolation(Interpolation): ...
5453

5554
class LegacyInterpolation(Interpolation):
56-
def before_get(self, parser: _parser, section: str, option: str, value: str, vars: _section) -> str: ...
55+
def before_get(self, parser: _Parser, section: str, option: str, value: str, vars: _Section) -> str: ...
5756

58-
class RawConfigParser(_parser):
57+
class RawConfigParser(_Parser):
5958
_SECT_TMPL: ClassVar[str] # undocumented
6059
_OPT_TMPL: ClassVar[str] # undocumented
6160
_OPT_NV_TMPL: ClassVar[str] # undocumented
@@ -81,12 +80,12 @@ class RawConfigParser(_parser):
8180
empty_lines_in_values: bool = ...,
8281
default_section: str = ...,
8382
interpolation: Interpolation | None = ...,
84-
converters: _converters = ...,
83+
converters: _ConvertersMap = ...,
8584
) -> None: ...
8685
@overload
8786
def __init__(
8887
self,
89-
defaults: _section | None = ...,
88+
defaults: _Section | None = ...,
9089
dict_type: type[Mapping[str, str]] = ...,
9190
allow_no_value: bool = ...,
9291
*,
@@ -97,15 +96,15 @@ class RawConfigParser(_parser):
9796
empty_lines_in_values: bool = ...,
9897
default_section: str = ...,
9998
interpolation: Interpolation | None = ...,
100-
converters: _converters = ...,
99+
converters: _ConvertersMap = ...,
101100
) -> None: ...
102101
def __len__(self) -> int: ...
103102
def __getitem__(self, key: str) -> SectionProxy: ...
104-
def __setitem__(self, key: str, value: _section) -> None: ...
103+
def __setitem__(self, key: str, value: _Section) -> None: ...
105104
def __delitem__(self, key: str) -> None: ...
106105
def __iter__(self) -> Iterator[str]: ...
107106
def __contains__(self, key: object) -> bool: ...
108-
def defaults(self) -> _section: ...
107+
def defaults(self) -> _Section: ...
109108
def sections(self) -> list[str]: ...
110109
def add_section(self, section: str) -> None: ...
111110
def has_section(self, section: str) -> bool: ...
@@ -119,22 +118,22 @@ class RawConfigParser(_parser):
119118
# These get* methods are partially applied (with the same names) in
120119
# SectionProxy; the stubs should be kept updated together
121120
@overload
122-
def getint(self, section: str, option: str, *, raw: bool = ..., vars: _section | None = ...) -> int: ...
121+
def getint(self, section: str, option: str, *, raw: bool = ..., vars: _Section | None = ...) -> int: ...
123122
@overload
124123
def getint(
125-
self, section: str, option: str, *, raw: bool = ..., vars: _section | None = ..., fallback: _T = ...
124+
self, section: str, option: str, *, raw: bool = ..., vars: _Section | None = ..., fallback: _T = ...
126125
) -> int | _T: ...
127126
@overload
128-
def getfloat(self, section: str, option: str, *, raw: bool = ..., vars: _section | None = ...) -> float: ...
127+
def getfloat(self, section: str, option: str, *, raw: bool = ..., vars: _Section | None = ...) -> float: ...
129128
@overload
130129
def getfloat(
131-
self, section: str, option: str, *, raw: bool = ..., vars: _section | None = ..., fallback: _T = ...
130+
self, section: str, option: str, *, raw: bool = ..., vars: _Section | None = ..., fallback: _T = ...
132131
) -> float | _T: ...
133132
@overload
134-
def getboolean(self, section: str, option: str, *, raw: bool = ..., vars: _section | None = ...) -> bool: ...
133+
def getboolean(self, section: str, option: str, *, raw: bool = ..., vars: _Section | None = ...) -> bool: ...
135134
@overload
136135
def getboolean(
137-
self, section: str, option: str, *, raw: bool = ..., vars: _section | None = ..., fallback: _T = ...
136+
self, section: str, option: str, *, raw: bool = ..., vars: _Section | None = ..., fallback: _T = ...
138137
) -> bool | _T: ...
139138
def _get_conv(
140139
self,
@@ -143,18 +142,18 @@ class RawConfigParser(_parser):
143142
conv: Callable[[str], _T],
144143
*,
145144
raw: bool = ...,
146-
vars: _section | None = ...,
145+
vars: _Section | None = ...,
147146
fallback: _T = ...,
148147
) -> _T: ...
149148
# This is incompatible with MutableMapping so we ignore the type
150149
@overload # type: ignore[override]
151-
def get(self, section: str, option: str, *, raw: bool = ..., vars: _section | None = ...) -> str: ...
150+
def get(self, section: str, option: str, *, raw: bool = ..., vars: _Section | None = ...) -> str: ...
152151
@overload
153-
def get(self, section: str, option: str, *, raw: bool = ..., vars: _section | None = ..., fallback: _T) -> str | _T: ...
152+
def get(self, section: str, option: str, *, raw: bool = ..., vars: _Section | None = ..., fallback: _T) -> str | _T: ...
154153
@overload
155-
def items(self, *, raw: bool = ..., vars: _section | None = ...) -> ItemsView[str, SectionProxy]: ...
154+
def items(self, *, raw: bool = ..., vars: _Section | None = ...) -> ItemsView[str, SectionProxy]: ...
156155
@overload
157-
def items(self, section: str, raw: bool = ..., vars: _section | None = ...) -> list[tuple[str, str]]: ...
156+
def items(self, section: str, raw: bool = ..., vars: _Section | None = ...) -> list[tuple[str, str]]: ...
158157
def set(self, section: str, option: str, value: str | None = ...) -> None: ...
159158
def write(self, fp: SupportsWrite[str], space_around_delimiters: bool = ...) -> None: ...
160159
def remove_option(self, section: str, option: str) -> bool: ...
@@ -184,32 +183,32 @@ class SectionProxy(MutableMapping[str, str]):
184183
fallback: str | None = ...,
185184
*,
186185
raw: bool = ...,
187-
vars: _section | None = ...,
186+
vars: _Section | None = ...,
188187
_impl: Any | None = ...,
189188
**kwargs: Any,
190189
) -> str: ...
191190
# These are partially-applied version of the methods with the same names in
192191
# RawConfigParser; the stubs should be kept updated together
193192
@overload
194-
def getint(self, option: str, *, raw: bool = ..., vars: _section | None = ...) -> int: ...
193+
def getint(self, option: str, *, raw: bool = ..., vars: _Section | None = ...) -> int: ...
195194
@overload
196-
def getint(self, option: str, fallback: _T = ..., *, raw: bool = ..., vars: _section | None = ...) -> int | _T: ...
195+
def getint(self, option: str, fallback: _T = ..., *, raw: bool = ..., vars: _Section | None = ...) -> int | _T: ...
197196
@overload
198-
def getfloat(self, option: str, *, raw: bool = ..., vars: _section | None = ...) -> float: ...
197+
def getfloat(self, option: str, *, raw: bool = ..., vars: _Section | None = ...) -> float: ...
199198
@overload
200-
def getfloat(self, option: str, fallback: _T = ..., *, raw: bool = ..., vars: _section | None = ...) -> float | _T: ...
199+
def getfloat(self, option: str, fallback: _T = ..., *, raw: bool = ..., vars: _Section | None = ...) -> float | _T: ...
201200
@overload
202-
def getboolean(self, option: str, *, raw: bool = ..., vars: _section | None = ...) -> bool: ...
201+
def getboolean(self, option: str, *, raw: bool = ..., vars: _Section | None = ...) -> bool: ...
203202
@overload
204-
def getboolean(self, option: str, fallback: _T = ..., *, raw: bool = ..., vars: _section | None = ...) -> bool | _T: ...
203+
def getboolean(self, option: str, fallback: _T = ..., *, raw: bool = ..., vars: _Section | None = ...) -> bool | _T: ...
205204
# SectionProxy can have arbitrary attributes when custom converters are used
206205
def __getattr__(self, key: str) -> Callable[..., Any]: ...
207206

208-
class ConverterMapping(MutableMapping[str, _converter | None]):
209-
GETTERCRE: Pattern[Any]
207+
class ConverterMapping(MutableMapping[str, _ConverterCallback | None]):
208+
GETTERCRE: ClassVar[Pattern[Any]]
210209
def __init__(self, parser: RawConfigParser) -> None: ...
211-
def __getitem__(self, key: str) -> _converter: ...
212-
def __setitem__(self, key: str, value: _converter | None) -> None: ...
210+
def __getitem__(self, key: str) -> _ConverterCallback: ...
211+
def __setitem__(self, key: str, value: _ConverterCallback | None) -> None: ...
213212
def __delitem__(self, key: str) -> None: ...
214213
def __iter__(self) -> Iterator[str]: ...
215214
def __len__(self) -> int: ...

0 commit comments

Comments
 (0)