77
77
"MAX_INTERPOLATION_DEPTH" ,
78
78
]
79
79
80
+ if sys .version_info >= (3 , 13 ):
81
+ class _UNNAMED_SECTION : ...
82
+ UNNAMED_SECTION : _UNNAMED_SECTION
83
+
84
+ _SectionName : TypeAlias = str | _UNNAMED_SECTION
85
+ # A list of sections can only include an unnamed section if the parser was initialized with
86
+ # allow_unnamed_section=True. Any prevents users from having to use explicit
87
+ # type checks if allow_unnamed_section is False (the default).
88
+ _SectionNameList : TypeAlias = list [Any ]
89
+ else :
90
+ _SectionName : TypeAlias = str
91
+ _SectionNameList : TypeAlias = list [str ]
92
+
80
93
_Section : TypeAlias = Mapping [str , str ]
81
94
_Parser : TypeAlias = MutableMapping [str , _Section ]
82
95
_ConverterCallback : TypeAlias = Callable [[str ], Any ]
@@ -87,17 +100,17 @@ DEFAULTSECT: Final = "DEFAULT"
87
100
MAX_INTERPOLATION_DEPTH : Final = 10
88
101
89
102
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 : ...
103
+ def before_get (self , parser : _Parser , section : _SectionName , option : str , value : str , defaults : _Section ) -> str : ...
104
+ def before_set (self , parser : _Parser , section : _SectionName , option : str , value : str ) -> str : ...
105
+ def before_read (self , parser : _Parser , section : _SectionName , option : str , value : str ) -> str : ...
106
+ def before_write (self , parser : _Parser , section : _SectionName , option : str , value : str ) -> str : ...
94
107
95
108
class BasicInterpolation (Interpolation ): ...
96
109
class ExtendedInterpolation (Interpolation ): ...
97
110
98
111
if sys .version_info < (3 , 13 ):
99
112
class LegacyInterpolation (Interpolation ):
100
- def before_get (self , parser : _Parser , section : str , option : str , value : str , vars : _Section ) -> str : ...
113
+ def before_get (self , parser : _Parser , section : _SectionName , option : str , value : str , vars : _Section ) -> str : ...
101
114
102
115
class RawConfigParser (_Parser ):
103
116
_SECT_TMPL : ClassVar [str ] # undocumented
@@ -220,11 +233,11 @@ class RawConfigParser(_Parser):
220
233
def __iter__ (self ) -> Iterator [str ]: ...
221
234
def __contains__ (self , key : object ) -> bool : ...
222
235
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 : ...
236
+ def sections (self ) -> _SectionNameList : ...
237
+ def add_section (self , section : _SectionName ) -> None : ...
238
+ def has_section (self , section : _SectionName ) -> bool : ...
239
+ def options (self , section : _SectionName ) -> list [str ]: ...
240
+ def has_option (self , section : _SectionName , option : str ) -> bool : ...
228
241
def read (self , filenames : StrOrBytesPath | Iterable [StrOrBytesPath ], encoding : str | None = None ) -> list [str ]: ...
229
242
def read_file (self , f : Iterable [str ], source : str | None = None ) -> None : ...
230
243
def read_string (self , string : str , source : str = "<string>" ) -> None : ...
@@ -234,26 +247,26 @@ class RawConfigParser(_Parser):
234
247
# These get* methods are partially applied (with the same names) in
235
248
# SectionProxy; the stubs should be kept updated together
236
249
@overload
237
- def getint (self , section : str , option : str , * , raw : bool = False , vars : _Section | None = None ) -> int : ...
250
+ def getint (self , section : _SectionName , option : str , * , raw : bool = False , vars : _Section | None = None ) -> int : ...
238
251
@overload
239
252
def getint (
240
- self , section : str , option : str , * , raw : bool = False , vars : _Section | None = None , fallback : _T = ...
253
+ self , section : _SectionName , option : str , * , raw : bool = False , vars : _Section | None = None , fallback : _T = ...
241
254
) -> int | _T : ...
242
255
@overload
243
- def getfloat (self , section : str , option : str , * , raw : bool = False , vars : _Section | None = None ) -> float : ...
256
+ def getfloat (self , section : _SectionName , option : str , * , raw : bool = False , vars : _Section | None = None ) -> float : ...
244
257
@overload
245
258
def getfloat (
246
- self , section : str , option : str , * , raw : bool = False , vars : _Section | None = None , fallback : _T = ...
259
+ self , section : _SectionName , option : str , * , raw : bool = False , vars : _Section | None = None , fallback : _T = ...
247
260
) -> float | _T : ...
248
261
@overload
249
- def getboolean (self , section : str , option : str , * , raw : bool = False , vars : _Section | None = None ) -> bool : ...
262
+ def getboolean (self , section : _SectionName , option : str , * , raw : bool = False , vars : _Section | None = None ) -> bool : ...
250
263
@overload
251
264
def getboolean (
252
- self , section : str , option : str , * , raw : bool = False , vars : _Section | None = None , fallback : _T = ...
265
+ self , section : _SectionName , option : str , * , raw : bool = False , vars : _Section | None = None , fallback : _T = ...
253
266
) -> bool | _T : ...
254
267
def _get_conv (
255
268
self ,
256
- section : str ,
269
+ section : _SectionName ,
257
270
option : str ,
258
271
conv : Callable [[str ], _T ],
259
272
* ,
@@ -263,29 +276,31 @@ class RawConfigParser(_Parser):
263
276
) -> _T : ...
264
277
# This is incompatible with MutableMapping so we ignore the type
265
278
@overload # type: ignore[override]
266
- def get (self , section : str , option : str , * , raw : bool = False , vars : _Section | None = None ) -> str | MaybeNone : ...
279
+ def get (self , section : _SectionName , option : str , * , raw : bool = False , vars : _Section | None = None ) -> str | MaybeNone : ...
267
280
@overload
268
281
def get (
269
- self , section : str , option : str , * , raw : bool = False , vars : _Section | None = None , fallback : _T
282
+ self , section : _SectionName , option : str , * , raw : bool = False , vars : _Section | None = None , fallback : _T
270
283
) -> str | _T | MaybeNone : ...
271
284
@overload
272
285
def items (self , * , raw : bool = False , vars : _Section | None = None ) -> ItemsView [str , SectionProxy ]: ...
273
286
@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 : ...
287
+ def items (self , section : _SectionName , raw : bool = False , vars : _Section | None = None ) -> list [tuple [str , str ]]: ...
288
+ def set (self , section : _SectionName , option : str , value : str | None = None ) -> None : ...
276
289
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 : ...
290
+ def remove_option (self , section : _SectionName , option : str ) -> bool : ...
291
+ def remove_section (self , section : _SectionName ) -> bool : ...
279
292
def optionxform (self , optionstr : str ) -> str : ...
280
293
@property
281
294
def converters (self ) -> ConverterMapping : ...
282
295
283
296
class ConfigParser (RawConfigParser ):
284
297
# This is incompatible with MutableMapping so we ignore the type
285
298
@overload # type: ignore[override]
286
- def get (self , section : str , option : str , * , raw : bool = False , vars : _Section | None = None ) -> str : ...
299
+ def get (self , section : _SectionName , option : str , * , raw : bool = False , vars : _Section | None = None ) -> str : ...
287
300
@overload
288
- def get (self , section : str , option : str , * , raw : bool = False , vars : _Section | None = None , fallback : _T ) -> str | _T : ...
301
+ def get (
302
+ self , section : _SectionName , option : str , * , raw : bool = False , vars : _Section | None = None , fallback : _T
303
+ ) -> str | _T : ...
289
304
290
305
if sys .version_info < (3 , 12 ):
291
306
class SafeConfigParser (ConfigParser ): ... # deprecated alias
@@ -349,38 +364,38 @@ class Error(Exception):
349
364
def __init__ (self , msg : str = "" ) -> None : ...
350
365
351
366
class NoSectionError (Error ):
352
- section : str
353
- def __init__ (self , section : str ) -> None : ...
367
+ section : _SectionName
368
+ def __init__ (self , section : _SectionName ) -> None : ...
354
369
355
370
class DuplicateSectionError (Error ):
356
- section : str
371
+ section : _SectionName
357
372
source : str | None
358
373
lineno : int | None
359
- def __init__ (self , section : str , source : str | None = None , lineno : int | None = None ) -> None : ...
374
+ def __init__ (self , section : _SectionName , source : str | None = None , lineno : int | None = None ) -> None : ...
360
375
361
376
class DuplicateOptionError (Error ):
362
- section : str
377
+ section : _SectionName
363
378
option : str
364
379
source : str | None
365
380
lineno : int | None
366
- def __init__ (self , section : str , option : str , source : str | None = None , lineno : int | None = None ) -> None : ...
381
+ def __init__ (self , section : _SectionName , option : str , source : str | None = None , lineno : int | None = None ) -> None : ...
367
382
368
383
class NoOptionError (Error ):
369
- section : str
384
+ section : _SectionName
370
385
option : str
371
- def __init__ (self , option : str , section : str ) -> None : ...
386
+ def __init__ (self , option : str , section : _SectionName ) -> None : ...
372
387
373
388
class InterpolationError (Error ):
374
- section : str
389
+ section : _SectionName
375
390
option : str
376
- def __init__ (self , option : str , section : str , msg : str ) -> None : ...
391
+ def __init__ (self , option : str , section : _SectionName , msg : str ) -> None : ...
377
392
378
393
class InterpolationDepthError (InterpolationError ):
379
- def __init__ (self , option : str , section : str , rawval : object ) -> None : ...
394
+ def __init__ (self , option : str , section : _SectionName , rawval : object ) -> None : ...
380
395
381
396
class InterpolationMissingOptionError (InterpolationError ):
382
397
reference : str
383
- def __init__ (self , option : str , section : str , rawval : object , reference : str ) -> None : ...
398
+ def __init__ (self , option : str , section : _SectionName , rawval : object , reference : str ) -> None : ...
384
399
385
400
class InterpolationSyntaxError (InterpolationError ): ...
386
401
@@ -403,9 +418,6 @@ class MissingSectionHeaderError(ParsingError):
403
418
def __init__ (self , filename : str , lineno : int , line : str ) -> None : ...
404
419
405
420
if sys .version_info >= (3 , 13 ):
406
- class _UNNAMED_SECTION : ...
407
- UNNAMED_SECTION : _UNNAMED_SECTION
408
-
409
421
class MultilineContinuationError (ParsingError ):
410
422
lineno : int
411
423
line : str
0 commit comments