1
1
# Stubs for argparse (Python 2.7 and 3.4)
2
2
3
3
from typing import (
4
- Any , Callable , Iterable , List , IO , Optional , Sequence , Tuple , Type , Union ,
5
- TypeVar , overload
4
+ Any , Callable , Dict , Generator , Iterable , List , IO , NoReturn , Optional ,
5
+ Pattern , Sequence , Tuple , Type , Union , TypeVar , overload
6
6
)
7
7
import sys
8
8
9
9
_T = TypeVar ('_T' )
10
+ _ActionT = TypeVar ('_ActionT' , bound = 'Action' )
10
11
11
12
if sys .version_info >= (3 ,):
12
13
_Text = str
13
14
else :
14
15
_Text = Union [str , unicode ]
15
16
16
- ONE_OR_MORE = ... # type: str
17
- OPTIONAL = ... # type: str
18
- PARSER = ... # type: str
19
- REMAINDER = ... # type: str
20
- SUPPRESS = ... # type: str
21
- ZERO_OR_MORE = ... # type: str
17
+ ONE_OR_MORE : str
18
+ OPTIONAL : str
19
+ PARSER : str
20
+ REMAINDER : str
21
+ SUPPRESS : str
22
+ ZERO_OR_MORE : str
23
+ _UNRECOGNIZED_ARGS_ATTR : str # undocumented
22
24
23
25
class ArgumentError (Exception ): ...
24
26
25
- class ArgumentParser :
26
- prog = ... # type: _Text
27
- usage = ... # type: Optional[_Text]
28
- description = ... # type: Optional[_Text]
29
- epilog = ... # type: Optional[_Text]
30
- formatter_class = ... # type: Type[HelpFormatter]
31
- prefix_chars = ... # type: _Text
32
- fromfile_prefix_chars = ... # type: Optional[_Text]
33
- argument_default = ... # type: Optional[_Text]
34
- conflict_handler = ... # type: _Text
35
- add_help = ... # type: bool
27
+ # undocumented
28
+ class _AttributeHolder :
29
+ def _get_kwargs (self ) -> List [Tuple [str , Any ]]: ...
30
+ def _get_args (self ) -> List [Any ]: ...
31
+
32
+ # undocumented
33
+ class _ActionsContainer :
34
+ description : Optional [_Text ]
35
+ prefix_chars : _Text
36
+ argument_default : Optional [_Text ]
37
+ conflict_handler : _Text
38
+
39
+ _registries : Dict [_Text , Dict [Any , Any ]]
40
+ _actions : List [Action ]
41
+ _option_string_actions : Dict [_Text , Action ]
42
+ _action_groups : List [_ArgumentGroup ]
43
+ _mutually_exclusive_groups : List [_MutuallyExclusiveGroup ]
44
+ _defaults : Dict [str , Any ]
45
+ _negative_number_matcher : Pattern [str ]
46
+ _has_negative_number_optionals : List [bool ]
47
+
48
+ def __init__ (self , description : Optional [_Text ], prefix_chars : _Text ,
49
+ argument_default : Optional [_Text ], conflict_handler : _Text ) -> None : ...
50
+ def register (self , registry_name : _Text , value : Any , object : Any ) -> None : ...
51
+ def _registry_get (self , registry_name : _Text , value : Any , default : Any = ...) -> Any : ...
52
+ def set_defaults (self , ** kwargs : Any ) -> None : ...
53
+ def get_default (self , dest : _Text ) -> Any : ...
54
+ def add_argument (self ,
55
+ * name_or_flags : _Text ,
56
+ action : Union [_Text , Type [Action ]] = ...,
57
+ nargs : Union [int , _Text ] = ...,
58
+ const : Any = ...,
59
+ default : Any = ...,
60
+ type : Union [Callable [[_Text ], _T ], FileType ] = ...,
61
+ choices : Iterable [_T ] = ...,
62
+ required : bool = ...,
63
+ help : _Text = ...,
64
+ metavar : Union [_Text , Tuple [_Text , ...]] = ...,
65
+ dest : _Text = ...,
66
+ version : _Text = ...) -> Action : ...
67
+ def add_argument_group (self , * args : Any , ** kwargs : Any ) -> _ArgumentGroup : ...
68
+ def add_mutually_exclusive_group (self , ** kwargs : Any ) -> _MutuallyExclusiveGroup : ...
69
+ def _add_action (self , action : _ActionT ) -> _ActionT : ...
70
+ def _remove_action (self , action : Action ) -> None : ...
71
+ def _add_container_actions (self , container : _ActionsContainer ) -> None : ...
72
+ def _get_positional_kwargs (self , dest : _Text , ** kwargs : Any ) -> Dict [str , Any ]: ...
73
+ def _get_optional_kwargs (self , * args : Any , ** kwargs : Any ) -> Dict [str , Any ]: ...
74
+ def _pop_action_class (self , kwargs : Any , default : Optional [Type [Action ]] = ...) -> Type [Action ]: ...
75
+ def _get_handler (self ) -> Callable [[Action , Iterable [Tuple [_Text , Action ]]], Any ]: ...
76
+ def _check_conflict (self , action : Action ) -> None : ...
77
+ def _handle_conflict_error (self , action : Action , conflicting_actions : Iterable [Tuple [_Text , Action ]]) -> NoReturn : ...
78
+ def _handle_conflict_resolve (self , action : Action , conflicting_actions : Iterable [Tuple [_Text , Action ]]) -> None : ...
79
+
80
+ class ArgumentParser (_AttributeHolder , _ActionsContainer ):
81
+ prog : _Text
82
+ usage : Optional [_Text ]
83
+ epilog : Optional [_Text ]
84
+ formatter_class : Type [HelpFormatter ]
85
+ fromfile_prefix_chars : Optional [_Text ]
86
+ add_help : bool
36
87
37
88
if sys .version_info >= (3 , 5 ):
38
- allow_abbrev = ... # type: bool
89
+ allow_abbrev : bool
90
+
91
+ # undocumented
92
+ _positionals : _ArgumentGroup
93
+ _optionals : _ArgumentGroup
94
+ _subparsers : Optional [_ArgumentGroup ]
39
95
40
96
if sys .version_info >= (3 , 5 ):
41
97
def __init__ (self ,
@@ -64,19 +120,6 @@ class ArgumentParser:
64
120
argument_default : Optional [_Text ] = ...,
65
121
conflict_handler : _Text = ...,
66
122
add_help : bool = ...) -> None : ...
67
- def add_argument (self ,
68
- * name_or_flags : Union [_Text , Sequence [_Text ]],
69
- action : Union [_Text , Type [Action ]] = ...,
70
- nargs : Union [int , _Text ] = ...,
71
- const : Any = ...,
72
- default : Any = ...,
73
- type : Union [Callable [[str ], _T ], FileType ] = ...,
74
- choices : Iterable [_T ] = ...,
75
- required : bool = ...,
76
- help : _Text = ...,
77
- metavar : Union [_Text , Tuple [_Text , ...]] = ...,
78
- dest : Optional [_Text ] = ...,
79
- version : _Text = ...) -> Action : ...
80
123
def parse_args (self , args : Optional [Sequence [_Text ]] = ...,
81
124
namespace : Optional [Namespace ] = ...) -> Namespace : ...
82
125
def add_subparsers (self , title : _Text = ...,
@@ -88,11 +131,6 @@ class ArgumentParser:
88
131
dest : Optional [_Text ] = ...,
89
132
help : Optional [_Text ] = ...,
90
133
metavar : Optional [_Text ] = ...) -> _SubParsersAction : ...
91
- def add_argument_group (self , title : Optional [_Text ] = ...,
92
- description : Optional [_Text ] = ...) -> _ArgumentGroup : ...
93
- def add_mutually_exclusive_group (self , required : bool = ...) -> _MutuallyExclusiveGroup : ...
94
- def set_defaults (self , ** kwargs : Any ) -> None : ...
95
- def get_default (self , dest : _Text ) -> Any : ...
96
134
def print_usage (self , file : Optional [IO [str ]] = ...) -> None : ...
97
135
def print_help (self , file : Optional [IO [str ]] = ...) -> None : ...
98
136
def format_usage (self ) -> str : ...
@@ -102,19 +140,78 @@ class ArgumentParser:
102
140
def convert_arg_line_to_args (self , arg_line : _Text ) -> List [str ]: ...
103
141
def exit (self , status : int = ..., message : Optional [_Text ] = ...) -> None : ...
104
142
def error (self , message : _Text ) -> None : ...
143
+ if sys .version_info >= (3 , 7 ):
144
+ def parse_intermixed_args (self , args : Optional [Sequence [_Text ]] = ...,
145
+ namespace : Optional [Namespace ] = ...) -> Namespace : ...
146
+ def parse_known_intermixed_args (self ,
147
+ args : Optional [Sequence [_Text ]] = ...,
148
+ namespace : Optional [Namespace ] = ...) -> Tuple [Namespace , List [str ]]: ...
149
+ # undocumented
150
+ def _get_optional_actions (self ) -> List [Action ]: ...
151
+ def _get_positional_actions (self ) -> List [Action ]: ...
152
+ def _parse_known_args (self , arg_strings : List [_Text ], namespace : Namespace ) -> Tuple [Namespace , List [str ]]: ...
153
+ def _read_args_from_files (self , arg_strings : List [_Text ]) -> List [_Text ]: ...
154
+ def _match_argument (self , action : Action , arg_strings_pattern : _Text ) -> int : ...
155
+ def _match_arguments_partial (self , actions : Sequence [Action ], arg_strings_pattern : _Text ) -> List [int ]: ...
156
+ def _parse_optional (self , arg_string : _Text ) -> Optional [Tuple [Optional [Action ], _Text , Optional [_Text ]]]: ...
157
+ def _get_option_tuples (self , option_string : _Text ) -> List [Tuple [Action , _Text , Optional [_Text ]]]: ...
158
+ def _get_nargs_pattern (self , action : Action ) -> _Text : ...
159
+ def _get_values (self , action : Action , arg_strings : List [_Text ]) -> Any : ...
160
+ def _get_value (self , action : Action , arg_string : _Text ) -> Any : ...
161
+ def _check_value (self , action : Action , value : Any ) -> None : ...
162
+ def _get_formatter (self ) -> HelpFormatter : ...
163
+ def _print_message (self , message : str , file : Optional [IO [str ]] = ...) -> None : ...
105
164
106
165
class HelpFormatter :
107
- # not documented
166
+ # undocumented
167
+ _prog : _Text
168
+ _indent_increment : int
169
+ _max_help_position : int
170
+ _width : int
171
+ _current_indent : int
172
+ _level : int
173
+ _action_max_length : int
174
+ _root_section : Any
175
+ _current_section : Any
176
+ _whitespace_matcher : Pattern [str ]
177
+ _long_break_matcher : Pattern [str ]
178
+ _Section : Type [Any ] # Nested class
108
179
def __init__ (self , prog : _Text , indent_increment : int = ...,
109
180
max_help_position : int = ...,
110
181
width : Optional [int ] = ...) -> None : ...
182
+ def _indent (self ) -> None : ...
183
+ def _dedent (self ) -> None : ...
184
+ def _add_item (self , func : Callable [..., _Text ], args : Iterable [Any ]) -> None : ...
185
+ def start_section (self , heading : Optional [_Text ]) -> None : ...
186
+ def end_section (self ) -> None : ...
187
+ def add_text (self , text : Optional [_Text ]) -> None : ...
188
+ def add_usage (self , usage : _Text , actions : Iterable [Action ], groups : Iterable [_ArgumentGroup ], prefix : Optional [_Text ] = ...) -> None : ...
189
+ def add_argument (self , action : Action ) -> None : ...
190
+ def add_arguments (self , actions : Iterable [Action ]) -> None : ...
191
+ def format_help (self ) -> _Text : ...
192
+ def _join_parts (self , part_strings : Iterable [_Text ]) -> _Text : ...
193
+ def _format_usage (self , usage : _Text , actions : Iterable [Action ], groups : Iterable [_ArgumentGroup ], prefix : Optional [_Text ]) -> _Text : ...
194
+ def _format_actions_usage (self , actions : Iterable [Action ], groups : Iterable [_ArgumentGroup ]) -> _Text : ...
195
+ def _format_text (self , text : _Text ) -> _Text : ...
196
+ def _format_action (self , action : Action ) -> _Text : ...
197
+ def _format_action_invocation (self , action : Action ) -> _Text : ...
198
+ def _metavar_formatter (self , action : Action , default_metavar : _Text ) -> Callable [[int ], Tuple [_Text , ...]]: ...
199
+ def _format_args (self , action : Action , default_metavar : _Text ) -> _Text : ...
200
+ def _expand_help (self , action : Action ) -> _Text : ...
201
+ def _iter_indented_subactions (self , action : Action ) -> Generator [Action , None , None ]: ...
202
+ def _split_lines (self , text : _Text , width : int ) -> List [_Text ]: ...
203
+ def _fill_text (self , text : _Text , width : int , indent : int ) -> _Text : ...
204
+ def _get_help_string (self , action : Action ) -> Optional [_Text ]: ...
205
+ def _get_default_metavar_for_optional (self , action : Action ) -> _Text : ...
206
+ def _get_default_metavar_for_positional (self , action : Action ) -> _Text : ...
207
+
111
208
class RawDescriptionHelpFormatter (HelpFormatter ): ...
112
209
class RawTextHelpFormatter (HelpFormatter ): ...
113
210
class ArgumentDefaultsHelpFormatter (HelpFormatter ): ...
114
211
if sys .version_info >= (3 ,):
115
212
class MetavarTypeHelpFormatter (HelpFormatter ): ...
116
213
117
- class Action :
214
+ class Action ( _AttributeHolder ) :
118
215
option_strings : Sequence [_Text ]
119
216
dest : _Text
120
217
nargs : Optional [Union [int , _Text ]]
@@ -128,7 +225,7 @@ class Action:
128
225
129
226
def __init__ (self ,
130
227
option_strings : Sequence [_Text ],
131
- dest : _Text = ... ,
228
+ dest : _Text ,
132
229
nargs : Optional [Union [int , _Text ]] = ...,
133
230
const : Any = ...,
134
231
default : Any = ...,
@@ -141,13 +238,19 @@ class Action:
141
238
values : Union [_Text , Sequence [Any ], None ],
142
239
option_string : Optional [_Text ] = ...) -> None : ...
143
240
144
- class Namespace :
241
+ class Namespace ( _AttributeHolder ) :
145
242
def __init__ (self , ** kwargs : Any ) -> None : ...
146
243
def __getattr__ (self , name : _Text ) -> Any : ...
147
244
def __setattr__ (self , name : _Text , value : Any ) -> None : ...
148
245
def __contains__ (self , key : str ) -> bool : ...
149
246
150
247
class FileType :
248
+ # undocumented
249
+ _mode : _Text
250
+ _bufsize : int
251
+ if sys .version_info >= (3 , 4 ):
252
+ _encoding : Optional [_Text ]
253
+ _errors : Optional [_Text ]
151
254
if sys .version_info >= (3 , 4 ):
152
255
def __init__ (self , mode : _Text = ..., bufsize : int = ...,
153
256
encoding : Optional [_Text ] = ...,
@@ -160,27 +263,118 @@ class FileType:
160
263
mode : _Text = ..., bufsize : Optional [int ] = ...) -> None : ...
161
264
def __call__ (self , string : _Text ) -> IO [Any ]: ...
162
265
163
- class _ArgumentGroup :
164
- def add_argument (self ,
165
- * name_or_flags : Union [_Text , Sequence [_Text ]],
166
- action : Union [_Text , Type [Action ]] = ...,
167
- nargs : Union [int , _Text ] = ...,
168
- const : Any = ...,
169
- default : Any = ...,
170
- type : Union [Callable [[str ], _T ], FileType ] = ...,
171
- choices : Iterable [_T ] = ...,
172
- required : bool = ...,
173
- help : _Text = ...,
174
- metavar : Union [_Text , Tuple [_Text , ...]] = ...,
175
- dest : Optional [_Text ] = ...,
176
- version : _Text = ...) -> Action : ...
177
- def add_mutually_exclusive_group (self , required : bool = ...) -> _MutuallyExclusiveGroup : ...
266
+ # undocumented
267
+ class _ArgumentGroup (_ActionsContainer ):
268
+ title : Optional [_Text ]
269
+ _group_actions : List [Action ]
270
+ def __init__ (self , container : _ActionsContainer ,
271
+ title : Optional [_Text ] = ...,
272
+ description : Optional [_Text ] = ..., ** kwargs : Any ) -> None : ...
273
+
274
+ # undocumented
275
+ class _MutuallyExclusiveGroup (_ArgumentGroup ):
276
+ required : bool
277
+ _container : _ActionsContainer
278
+ def __init__ (self , container : _ActionsContainer , required : bool = ...) -> None : ...
178
279
179
- class _MutuallyExclusiveGroup (_ArgumentGroup ): ...
280
+ # undocumented
281
+ class _StoreAction (Action ): ...
180
282
181
- class _SubParsersAction :
283
+ # undocumented
284
+ class _StoreConstAction (Action ):
285
+ def __init__ (self ,
286
+ option_strings : Sequence [_Text ],
287
+ dest : _Text ,
288
+ const : Any ,
289
+ default : Any = ...,
290
+ required : bool = ...,
291
+ help : Optional [_Text ] = ...,
292
+ metavar : Optional [Union [_Text , Tuple [_Text , ...]]] = ...) -> None : ...
293
+
294
+ # undocumented
295
+ class _StoreTrueAction (_StoreConstAction ):
296
+ def __init__ (self ,
297
+ option_strings : Sequence [_Text ],
298
+ dest : _Text ,
299
+ default : bool = ...,
300
+ required : bool = ...,
301
+ help : Optional [_Text ] = ...) -> None : ...
302
+
303
+ # undocumented
304
+ class _StoreFalseAction (_StoreConstAction ):
305
+ def __init__ (self ,
306
+ option_strings : Sequence [_Text ],
307
+ dest : _Text ,
308
+ default : bool = ...,
309
+ required : bool = ...,
310
+ help : Optional [_Text ] = ...) -> None : ...
311
+
312
+ # undocumented
313
+ class _AppendAction (Action ): ...
314
+
315
+ # undocumented
316
+ class _AppendConstAction (Action ):
317
+ def __init__ (self ,
318
+ option_strings : Sequence [_Text ],
319
+ dest : _Text ,
320
+ const : Any ,
321
+ default : Any = ...,
322
+ required : bool = ...,
323
+ help : Optional [_Text ] = ...,
324
+ metavar : Optional [Union [_Text , Tuple [_Text , ...]]] = ...) -> None : ...
325
+
326
+ # undocumented
327
+ class _CountAction (Action ):
328
+ def __init__ (self ,
329
+ option_strings : Sequence [_Text ],
330
+ dest : _Text ,
331
+ default : Any = ...,
332
+ required : bool = ...,
333
+ help : Optional [_Text ] = ...) -> None : ...
334
+
335
+ # undocumented
336
+ class _HelpAction (Action ):
337
+ def __init__ (self ,
338
+ option_strings : Sequence [_Text ],
339
+ dest : _Text = ...,
340
+ default : _Text = ...,
341
+ help : Optional [_Text ] = ...) -> None : ...
342
+
343
+ # undocumented
344
+ class _VersionAction (Action ):
345
+ version : Optional [_Text ]
346
+ def __init__ (self ,
347
+ option_strings : Sequence [_Text ],
348
+ version : Optional [_Text ] = ...,
349
+ dest : _Text = ...,
350
+ default : _Text = ...,
351
+ help : _Text = ...) -> None : ...
352
+
353
+ # undocumented
354
+ class _SubParsersAction (Action ):
355
+ _ChoicesPseudoAction : Type [Any ] # nested class
356
+ _prog_prefix : _Text
357
+ _parser_class : Type [ArgumentParser ]
358
+ _name_parser_map : Dict [_Text , ArgumentParser ]
359
+ _choices_actions : List [Action ]
360
+ def __init__ (self ,
361
+ option_strings : Sequence [_Text ],
362
+ prog : _Text ,
363
+ parser_class : Type [ArgumentParser ],
364
+ dest : _Text = ...,
365
+ required : bool = ...,
366
+ help : Optional [_Text ] = ...,
367
+ metavar : Optional [Union [_Text , Tuple [_Text , ...]]] = ...) -> None : ...
182
368
# TODO: Type keyword args properly.
183
369
def add_parser (self , name : _Text , ** kwargs : Any ) -> ArgumentParser : ...
370
+ def _get_subactions (self ) -> List [Action ]: ...
184
371
185
- # not documented
372
+ # undocumented
186
373
class ArgumentTypeError (Exception ): ...
374
+
375
+ if sys .version_info < (3 , 7 ):
376
+ # undocumented
377
+ def _ensure_value (namespace : Namespace , name : _Text , value : Any ) -> Any : ...
378
+
379
+ # undocumented
380
+ def _get_action_name (argument : Optional [Action ]) -> Optional [str ]: ...
0 commit comments