1
- # Stubs for configparser
2
-
3
1
# Based on http://docs.python.org/3.5/library/configparser.html and on
4
2
# reading configparser.py.
5
3
6
4
from typing import (MutableMapping , Mapping , Dict , Sequence , List , Union ,
7
- Iterable , Iterator , Callable , Any , IO , overload , Optional )
5
+ Iterable , Iterator , Callable , Any , IO , overload , Optional , Pattern )
8
6
# Types only used in type comments only
9
7
from typing import Optional , Tuple # noqa
10
8
11
9
# Internal type aliases
12
- _section = Dict [str , str ]
10
+ _section = Mapping [str , str ]
13
11
_parser = MutableMapping [str , _section ]
14
- _converters = Dict [str , Callable [[str ], Any ]]
15
-
16
-
17
- DEFAULTSECT = ... # type: str
12
+ _converter = Callable [[str ], Any ]
13
+ _converters = Dict [str , _converter ]
18
14
15
+ DEFAULTSECT : str
16
+ MAX_INTERPOLATION_DEPTH : int
19
17
20
18
class Interpolation :
21
19
def before_get (self , parser : _parser ,
@@ -40,27 +38,24 @@ class Interpolation:
40
38
value : str ) -> str : ...
41
39
42
40
43
- class BasicInterpolation (Interpolation ):
44
- pass
45
-
46
-
47
- class ExtendedInterpolation (Interpolation ):
48
- pass
41
+ class BasicInterpolation (Interpolation ): ...
42
+ class ExtendedInterpolation (Interpolation ): ...
43
+ class LegacyInterpolation (Interpolation ): ...
49
44
50
45
51
46
class RawConfigParser (_parser ):
52
47
def __init__ (self ,
53
- defaults : _section = None ,
48
+ defaults : Optional [ _section ] = ... ,
54
49
dict_type : Mapping [str , str ] = ...,
55
50
allow_no_value : bool = ...,
56
51
* ,
57
52
delimiters : Sequence [str ] = ...,
58
53
comment_prefixes : Sequence [str ] = ...,
59
- inline_comment_prefixes : Sequence [str ] = None ,
54
+ inline_comment_prefixes : Optional [ Sequence [str ]] = ... ,
60
55
strict : bool = ...,
61
56
empty_lines_in_values : bool = ...,
62
57
default_section : str = ...,
63
- interpolation : Interpolation = None ) -> None : ...
58
+ interpolation : Optional [ Interpolation ] = ... ) -> None : ...
64
59
65
60
def __len__ (self ) -> int : ...
66
61
@@ -134,6 +129,33 @@ class ConfigParser(RawConfigParser):
134
129
interpolation : Interpolation = None ,
135
130
converters : _converters = ...) -> None : ...
136
131
132
+ class SafeConfigParser (ConfigParser ): ...
133
+
134
+ class SectionProxy (MutableMapping [str , str ]):
135
+ def __init__ (self , parser : RawConfigParser , name : str ) -> None : ...
136
+ def __getitem__ (self , key : str ) -> str : ...
137
+ def __setitem__ (self , key : str , value : str ) -> None : ...
138
+ def __delitem__ (self , key : str ) -> None : ...
139
+ def __contains__ (self , key : object ) -> bool : ...
140
+ def __len__ (self ) -> int : ...
141
+ def __iter__ (self ) -> Iterator [str ]: ...
142
+ @property
143
+ def parser (self ) -> RawConfigParser : ...
144
+ @property
145
+ def name (self ) -> str : ...
146
+ def get (self , option : str , fallback : Optional [str ] = ..., * , raw : bool = ..., vars : Optional [_section ] = ..., ** kwargs : Any ) -> str : ... # type: ignore
147
+ # SectionProxy can have arbitrary attributes when custon converters are used
148
+ def __getattr__ (self , key : str ) -> Callable [..., Any ]: ...
149
+
150
+ class ConverterMapping (MutableMapping [str , Optional [_converter ]]):
151
+ GETTERCRE : Pattern
152
+ def __init__ (self , parser : RawConfigParser ) -> None : ...
153
+ def __getitem__ (self , key : str ) -> _converter : ...
154
+ def __setitem__ (self , key : str , value : Optional [_converter ]) -> None : ...
155
+ def __delitem__ (self , key : str ) -> None : ...
156
+ def __iter__ (self ) -> Iterator [str ]: ...
157
+ def __len__ (self ) -> int : ...
158
+
137
159
138
160
class Error (Exception ):
139
161
pass
0 commit comments