77
77
"MAX_INTERPOLATION_DEPTH" ,
78
78
]
79
79
80
+ if sys .version_info >= (3 , 13 ):
81
+ _SectionName : TypeAlias = str | _UNNAMED_SECTION
82
+ else :
83
+ _SectionName : TypeAlias = str
84
+
80
85
_Section : TypeAlias = Mapping [str , str ]
81
86
_Parser : TypeAlias = MutableMapping [str , _Section ]
82
87
_ConverterCallback : TypeAlias = Callable [[str ], Any ]
@@ -87,17 +92,17 @@ DEFAULTSECT: Final = "DEFAULT"
87
92
MAX_INTERPOLATION_DEPTH : Final = 10
88
93
89
94
class Interpolation :
90
- def before_get (self , parser : _Parser , section : str , option : str , value : str , defaults : _Section ) -> str : ...
91
- def before_set (self , parser : _Parser , section : str , option : str , value : str ) -> str : ...
92
- def before_read (self , parser : _Parser , section : str , option : str , value : str ) -> str : ...
93
- def before_write (self , parser : _Parser , section : str , option : str , value : str ) -> str : ...
95
+ def before_get (self , parser : _Parser , section : _SectionName , option : str , value : str , defaults : _Section ) -> str : ...
96
+ def before_set (self , parser : _Parser , section : _SectionName , option : str , value : str ) -> str : ...
97
+ def before_read (self , parser : _Parser , section : _SectionName , option : str , value : str ) -> str : ...
98
+ def before_write (self , parser : _Parser , section : _SectionName , option : str , value : str ) -> str : ...
94
99
95
100
class BasicInterpolation (Interpolation ): ...
96
101
class ExtendedInterpolation (Interpolation ): ...
97
102
98
103
if sys .version_info < (3 , 13 ):
99
104
class LegacyInterpolation (Interpolation ):
100
- def before_get (self , parser : _Parser , section : str , option : str , value : str , vars : _Section ) -> str : ...
105
+ def before_get (self , parser : _Parser , section : _SectionName , option : str , value : str , vars : _Section ) -> str : ...
101
106
102
107
class RawConfigParser (_Parser ):
103
108
_SECT_TMPL : ClassVar [str ] # undocumented
@@ -220,11 +225,11 @@ class RawConfigParser(_Parser):
220
225
def __iter__ (self ) -> Iterator [str ]: ...
221
226
def __contains__ (self , key : object ) -> bool : ...
222
227
def defaults (self ) -> _Section : ...
223
- def sections (self ) -> list [str ]: ...
224
- def add_section (self , section : str ) -> None : ...
225
- def has_section (self , section : str ) -> bool : ...
226
- def options (self , section : str ) -> list [str ]: ...
227
- def has_option (self , section : str , option : str ) -> bool : ...
228
+ def sections (self ) -> list [_SectionName ]: ...
229
+ def add_section (self , section : _SectionName ) -> None : ...
230
+ def has_section (self , section : _SectionName ) -> bool : ...
231
+ def options (self , section : _SectionName ) -> list [str ]: ...
232
+ def has_option (self , section : _SectionName , option : str ) -> bool : ...
228
233
def read (self , filenames : StrOrBytesPath | Iterable [StrOrBytesPath ], encoding : str | None = None ) -> list [str ]: ...
229
234
def read_file (self , f : Iterable [str ], source : str | None = None ) -> None : ...
230
235
def read_string (self , string : str , source : str = "<string>" ) -> None : ...
@@ -234,26 +239,26 @@ class RawConfigParser(_Parser):
234
239
# These get* methods are partially applied (with the same names) in
235
240
# SectionProxy; the stubs should be kept updated together
236
241
@overload
237
- def getint (self , section : str , option : str , * , raw : bool = False , vars : _Section | None = None ) -> int : ...
242
+ def getint (self , section : _SectionName , option : str , * , raw : bool = False , vars : _Section | None = None ) -> int : ...
238
243
@overload
239
244
def getint (
240
- self , section : str , option : str , * , raw : bool = False , vars : _Section | None = None , fallback : _T = ...
245
+ self , section : _SectionName , option : str , * , raw : bool = False , vars : _Section | None = None , fallback : _T = ...
241
246
) -> int | _T : ...
242
247
@overload
243
- def getfloat (self , section : str , option : str , * , raw : bool = False , vars : _Section | None = None ) -> float : ...
248
+ def getfloat (self , section : _SectionName , option : str , * , raw : bool = False , vars : _Section | None = None ) -> float : ...
244
249
@overload
245
250
def getfloat (
246
- self , section : str , option : str , * , raw : bool = False , vars : _Section | None = None , fallback : _T = ...
251
+ self , section : _SectionName , option : str , * , raw : bool = False , vars : _Section | None = None , fallback : _T = ...
247
252
) -> float | _T : ...
248
253
@overload
249
- def getboolean (self , section : str , option : str , * , raw : bool = False , vars : _Section | None = None ) -> bool : ...
254
+ def getboolean (self , section : _SectionName , option : str , * , raw : bool = False , vars : _Section | None = None ) -> bool : ...
250
255
@overload
251
256
def getboolean (
252
- self , section : str , option : str , * , raw : bool = False , vars : _Section | None = None , fallback : _T = ...
257
+ self , section : _SectionName , option : str , * , raw : bool = False , vars : _Section | None = None , fallback : _T = ...
253
258
) -> bool | _T : ...
254
259
def _get_conv (
255
260
self ,
256
- section : str ,
261
+ section : _SectionName ,
257
262
option : str ,
258
263
conv : Callable [[str ], _T ],
259
264
* ,
@@ -263,29 +268,31 @@ class RawConfigParser(_Parser):
263
268
) -> _T : ...
264
269
# This is incompatible with MutableMapping so we ignore the type
265
270
@overload # type: ignore[override]
266
- def get (self , section : str , option : str , * , raw : bool = False , vars : _Section | None = None ) -> str | MaybeNone : ...
271
+ def get (self , section : _SectionName , option : str , * , raw : bool = False , vars : _Section | None = None ) -> str | MaybeNone : ...
267
272
@overload
268
273
def get (
269
- self , section : str , option : str , * , raw : bool = False , vars : _Section | None = None , fallback : _T
274
+ self , section : _SectionName , option : str , * , raw : bool = False , vars : _Section | None = None , fallback : _T
270
275
) -> str | _T | MaybeNone : ...
271
276
@overload
272
277
def items (self , * , raw : bool = False , vars : _Section | None = None ) -> ItemsView [str , SectionProxy ]: ...
273
278
@overload
274
- def items (self , section : str , raw : bool = False , vars : _Section | None = None ) -> list [tuple [str , str ]]: ...
275
- def set (self , section : str , option : str , value : str | None = None ) -> None : ...
279
+ def items (self , section : _SectionName , raw : bool = False , vars : _Section | None = None ) -> list [tuple [str , str ]]: ...
280
+ def set (self , section : _SectionName , option : str , value : str | None = None ) -> None : ...
276
281
def write (self , fp : SupportsWrite [str ], space_around_delimiters : bool = True ) -> None : ...
277
- def remove_option (self , section : str , option : str ) -> bool : ...
278
- def remove_section (self , section : str ) -> bool : ...
282
+ def remove_option (self , section : _SectionName , option : str ) -> bool : ...
283
+ def remove_section (self , section : _SectionName ) -> bool : ...
279
284
def optionxform (self , optionstr : str ) -> str : ...
280
285
@property
281
286
def converters (self ) -> ConverterMapping : ...
282
287
283
288
class ConfigParser (RawConfigParser ):
284
289
# This is incompatible with MutableMapping so we ignore the type
285
290
@overload # type: ignore[override]
286
- def get (self , section : str , option : str , * , raw : bool = False , vars : _Section | None = None ) -> str : ...
291
+ def get (self , section : _SectionName , option : str , * , raw : bool = False , vars : _Section | None = None ) -> str : ...
287
292
@overload
288
- def get (self , section : str , option : str , * , raw : bool = False , vars : _Section | None = None , fallback : _T ) -> str | _T : ...
293
+ def get (
294
+ self , section : _SectionName , option : str , * , raw : bool = False , vars : _Section | None = None , fallback : _T
295
+ ) -> str | _T : ...
289
296
290
297
if sys .version_info < (3 , 12 ):
291
298
class SafeConfigParser (ConfigParser ): ... # deprecated alias
@@ -349,38 +356,38 @@ class Error(Exception):
349
356
def __init__ (self , msg : str = "" ) -> None : ...
350
357
351
358
class NoSectionError (Error ):
352
- section : str
353
- def __init__ (self , section : str ) -> None : ...
359
+ section : _SectionName
360
+ def __init__ (self , section : _SectionName ) -> None : ...
354
361
355
362
class DuplicateSectionError (Error ):
356
- section : str
363
+ section : _SectionName
357
364
source : str | None
358
365
lineno : int | None
359
- def __init__ (self , section : str , source : str | None = None , lineno : int | None = None ) -> None : ...
366
+ def __init__ (self , section : _SectionName , source : str | None = None , lineno : int | None = None ) -> None : ...
360
367
361
368
class DuplicateOptionError (Error ):
362
- section : str
369
+ section : _SectionName
363
370
option : str
364
371
source : str | None
365
372
lineno : int | None
366
- def __init__ (self , section : str , option : str , source : str | None = None , lineno : int | None = None ) -> None : ...
373
+ def __init__ (self , section : _SectionName , option : str , source : str | None = None , lineno : int | None = None ) -> None : ...
367
374
368
375
class NoOptionError (Error ):
369
- section : str
376
+ section : _SectionName
370
377
option : str
371
- def __init__ (self , option : str , section : str ) -> None : ...
378
+ def __init__ (self , option : str , section : _SectionName ) -> None : ...
372
379
373
380
class InterpolationError (Error ):
374
- section : str
381
+ section : _SectionName
375
382
option : str
376
- def __init__ (self , option : str , section : str , msg : str ) -> None : ...
383
+ def __init__ (self , option : str , section : _SectionName , msg : str ) -> None : ...
377
384
378
385
class InterpolationDepthError (InterpolationError ):
379
- def __init__ (self , option : str , section : str , rawval : object ) -> None : ...
386
+ def __init__ (self , option : str , section : _SectionName , rawval : object ) -> None : ...
380
387
381
388
class InterpolationMissingOptionError (InterpolationError ):
382
389
reference : str
383
- def __init__ (self , option : str , section : str , rawval : object , reference : str ) -> None : ...
390
+ def __init__ (self , option : str , section : _SectionName , rawval : object , reference : str ) -> None : ...
384
391
385
392
class InterpolationSyntaxError (InterpolationError ): ...
386
393
0 commit comments