20 _ActionT = TypeVar("_ActionT", bound=Action)
21 _ArgumentParserT = TypeVar("_ArgumentParserT", bound=ArgumentParser)
30 _UNRECOGNIZED_ARGS_ATTR: str # undocumented
32 class ArgumentError(Exception):
33 argument_name: str | None
35 def __init__(self, argument: Action | None, message: str) -> None: ...
38 class _AttributeHolder:
39 def _get_kwargs(self) -> list[tuple[str, Any]]: ...
40 def _get_args(self) -> list[Any]: ...
43 class _ActionsContainer:
44 description: str | None
49 _registries: dict[str, dict[Any, Any]]
50 _actions: list[Action]
51 _option_string_actions: dict[str, Action]
52 _action_groups: list[_ArgumentGroup]
53 _mutually_exclusive_groups: list[_MutuallyExclusiveGroup]
54 _defaults: dict[str, Any]
55 _negative_number_matcher: Pattern[str]
56 _has_negative_number_optionals: list[bool]
57 def __init__(self, description: str | None, prefix_chars: str, argument_default: Any, conflict_handler: str) -> None: ...
58 def register(self, registry_name: str, value: Any, object: Any) -> None: ...
59 def _registry_get(self, registry_name: str, value: Any, default: Any = ...) -> Any: ...
60 def set_defaults(self, **kwargs: Any) -> None: ...
61 def get_default(self, dest: str) -> Any: ...
65 action: str | Type[Action] = ...,
66 nargs: int | str = ...,
69 type: Callable[[str], _T] | Callable[[str], _T] | FileType = ...,
70 choices: Iterable[_T] | None = ...,
72 help: str | None = ...,
73 metavar: str | Tuple[str, ...] | None = ...,
74 dest: str | None = ...,
78 def add_argument_group(self, *args: Any, **kwargs: Any) -> _ArgumentGroup: ...
79 def add_mutually_exclusive_group(self, **kwargs: Any) -> _MutuallyExclusiveGroup: ...
80 def _add_action(self, action: _ActionT) -> _ActionT: ...
81 def _remove_action(self, action: Action) -> None: ...
82 def _add_container_actions(self, container: _ActionsContainer) -> None: ...
83 def _get_positional_kwargs(self, dest: str, **kwargs: Any) -> dict[str, Any]: ...
84 def _get_optional_kwargs(self, *args: Any, **kwargs: Any) -> dict[str, Any]: ...
85 def _pop_action_class(self, kwargs: Any, default: Type[Action] | None = ...) -> Type[Action]: ...
86 def _get_handler(self) -> Callable[[Action, Iterable[tuple[str, Action]]], Any]: ...
87 def _check_conflict(self, action: Action) -> None: ...
88 def _handle_conflict_error(self, action: Action, conflicting_actions: Iterable[tuple[str, Action]]) -> NoReturn: ...
89 def _handle_conflict_resolve(self, action: Action, conflicting_actions: Iterable[tuple[str, Action]]) -> None: ...
91 class _FormatterClass(Protocol):
92 def __call__(self, prog: str) -> HelpFormatter: ...
94 class ArgumentParser(_AttributeHolder, _ActionsContainer):
98 formatter_class: _FormatterClass
99 fromfile_prefix_chars: str | None
104 _positionals: _ArgumentGroup
105 _optionals: _ArgumentGroup
106 _subparsers: _ArgumentGroup | None
108 if sys.version_info >= (3, 9):
111 prog: str | None = ...,
112 usage: str | None = ...,
113 description: str | None = ...,
114 epilog: str | None = ...,
115 parents: Sequence[ArgumentParser] = ...,
116 formatter_class: _FormatterClass = ...,
117 prefix_chars: str = ...,
118 fromfile_prefix_chars: str | None = ...,
119 argument_default: Any = ...,
120 conflict_handler: str = ...,
121 add_help: bool = ...,
122 allow_abbrev: bool = ...,
123 exit_on_error: bool = ...,
128 prog: str | None = ...,
129 usage: str | None = ...,
130 description: str | None = ...,
131 epilog: str | None = ...,
132 parents: Sequence[ArgumentParser] = ...,
133 formatter_class: _FormatterClass = ...,
134 prefix_chars: str = ...,
135 fromfile_prefix_chars: str | None = ...,
136 argument_default: Any = ...,
137 conflict_handler: str = ...,
138 add_help: bool = ...,
139 allow_abbrev: bool = ...,
141 # The type-ignores in these overloads should be temporary. See:
142 # https://github.com/python/typeshed/pull/2643#issuecomment-442280277
144 def parse_args(self, args: Sequence[str] | None = ...) -> Namespace: ...
146 def parse_args(self, args: Sequence[str] | None, namespace: None) -> Namespace: ... # type: ignore
148 def parse_args(self, args: Sequence[str] | None, namespace: _N) -> _N: ...
150 def parse_args(self, *, namespace: None) -> Namespace: ... # type: ignore
152 def parse_args(self, *, namespace: _N) -> _N: ...
153 if sys.version_info >= (3, 7):
156 self: _ArgumentParserT,
159 description: str | None = ...,
161 action: Type[Action] = ...,
162 option_string: str = ...,
163 dest: str | None = ...,
164 required: bool = ...,
165 help: str | None = ...,
166 metavar: str | None = ...,
167 ) -> _SubParsersAction[_ArgumentParserT]: ...
173 description: str | None = ...,
175 parser_class: Type[_ArgumentParserT] = ...,
176 action: Type[Action] = ...,
177 option_string: str = ...,
178 dest: str | None = ...,
179 required: bool = ...,
180 help: str | None = ...,
181 metavar: str | None = ...,
182 ) -> _SubParsersAction[_ArgumentParserT]: ...
186 self: _ArgumentParserT,
189 description: str | None = ...,
191 action: Type[Action] = ...,
192 option_string: str = ...,
193 dest: str | None = ...,
194 help: str | None = ...,
195 metavar: str | None = ...,
196 ) -> _SubParsersAction[_ArgumentParserT]: ...
202 description: str | None = ...,
204 parser_class: Type[_ArgumentParserT] = ...,
205 action: Type[Action] = ...,
206 option_string: str = ...,
207 dest: str | None = ...,
208 help: str | None = ...,
209 metavar: str | None = ...,
210 ) -> _SubParsersAction[_ArgumentParserT]: ...
211 def print_usage(self, file: IO[str] | None = ...) -> None: ...
212 def print_help(self, file: IO[str] | None = ...) -> None: ...
213 def format_usage(self) -> str: ...
214 def format_help(self) -> str: ...
215 def parse_known_args(
216 self, args: Sequence[str] | None = ..., namespace: Namespace | None = ...
217 ) -> tuple[Namespace, list[str]]: ...
218 def convert_arg_line_to_args(self, arg_line: str) -> list[str]: ...
219 def exit(self, status: int = ..., message: str | None = ...) -> NoReturn: ...
220 def error(self, message: str) -> NoReturn: ...
221 if sys.version_info >= (3, 7):
222 def parse_intermixed_args(self, args: Sequence[str] | None = ..., namespace: Namespace | None = ...) -> Namespace: ...
223 def parse_known_intermixed_args(
224 self, args: Sequence[str] | None = ..., namespace: Namespace | None = ...
225 ) -> tuple[Namespace, list[str]]: ...
227 def _get_optional_actions(self) -> list[Action]: ...
228 def _get_positional_actions(self) -> list[Action]: ...
229 def _parse_known_args(self, arg_strings: list[str], namespace: Namespace) -> tuple[Namespace, list[str]]: ...
230 def _read_args_from_files(self, arg_strings: list[str]) -> list[str]: ...
231 def _match_argument(self, action: Action, arg_strings_pattern: str) -> int: ...
232 def _match_arguments_partial(self, actions: Sequence[Action], arg_strings_pattern: str) -> list[int]: ...
233 def _parse_optional(self, arg_string: str) -> tuple[Action | None, str, str | None] | None: ...
234 def _get_option_tuples(self, option_string: str) -> list[tuple[Action, str, str | None]]: ...
235 def _get_nargs_pattern(self, action: Action) -> str: ...
236 def _get_values(self, action: Action, arg_strings: list[str]) -> Any: ...
237 def _get_value(self, action: Action, arg_string: str) -> Any: ...
238 def _check_value(self, action: Action, value: Any) -> None: ...
239 def _get_formatter(self) -> HelpFormatter: ...
240 def _print_message(self, message: str, file: IO[str] | None = ...) -> None: ...
245 _indent_increment: int
246 _max_help_position: int
250 _action_max_length: int
252 _current_section: Any
253 _whitespace_matcher: Pattern[str]
254 _long_break_matcher: Pattern[str]
255 _Section: Type[Any] # Nested class
256 def __init__(self, prog: str, indent_increment: int = ..., max_help_position: int = ..., width: int | None = ...) -> None: ...
257 def _indent(self) -> None: ...
258 def _dedent(self) -> None: ...
259 def _add_item(self, func: Callable[..., str], args: Iterable[Any]) -> None: ...
260 def start_section(self, heading: str | None) -> None: ...
261 def end_section(self) -> None: ...
262 def add_text(self, text: str | None) -> None: ...
264 self, usage: str | None, actions: Iterable[Action], groups: Iterable[_ArgumentGroup], prefix: str | None = ...
266 def add_argument(self, action: Action) -> None: ...
267 def add_arguments(self, actions: Iterable[Action]) -> None: ...
268 def format_help(self) -> str: ...
269 def _join_parts(self, part_strings: Iterable[str]) -> str: ...
271 self, usage: str, actions: Iterable[Action], groups: Iterable[_ArgumentGroup], prefix: str | None
273 def _format_actions_usage(self, actions: Iterable[Action], groups: Iterable[_ArgumentGroup]) -> str: ...
274 def _format_text(self, text: str) -> str: ...
275 def _format_action(self, action: Action) -> str: ...
276 def _format_action_invocation(self, action: Action) -> str: ...
277 def _metavar_formatter(self, action: Action, default_metavar: str) -> Callable[[int], Tuple[str, ...]]: ...
278 def _format_args(self, action: Action, default_metavar: str) -> str: ...
279 def _expand_help(self, action: Action) -> str: ...
280 def _iter_indented_subactions(self, action: Action) -> Generator[Action, None, None]: ...
281 def _split_lines(self, text: str, width: int) -> list[str]: ...
282 def _fill_text(self, text: str, width: int, indent: str) -> str: ...
283 def _get_help_string(self, action: Action) -> str | None: ...
284 def _get_default_metavar_for_optional(self, action: Action) -> str: ...
285 def _get_default_metavar_for_positional(self, action: Action) -> str: ...
287 class RawDescriptionHelpFormatter(HelpFormatter): ...
288 class RawTextHelpFormatter(RawDescriptionHelpFormatter): ...
289 class ArgumentDefaultsHelpFormatter(HelpFormatter): ...
290 class MetavarTypeHelpFormatter(HelpFormatter): ...
292 class Action(_AttributeHolder):
293 option_strings: Sequence[str]
295 nargs: int | str | None
298 type: Callable[[str], Any] | FileType | None
299 choices: Iterable[Any] | None
302 metavar: str | Tuple[str, ...] | None
305 option_strings: Sequence[str],
307 nargs: int | str | None = ...,
308 const: _T | None = ...,
309 default: _T | str | None = ...,
310 type: Callable[[str], _T] | Callable[[str], _T] | FileType | None = ...,
311 choices: Iterable[_T] | None = ...,
312 required: bool = ...,
313 help: str | None = ...,
314 metavar: str | Tuple[str, ...] | None = ...,
317 self, parser: ArgumentParser, namespace: Namespace, values: str | Sequence[Any] | None, option_string: str | None = ...
319 if sys.version_info >= (3, 9):
320 def format_usage(self) -> str: ...
322 if sys.version_info >= (3, 9):
323 class BooleanOptionalAction(Action):
326 option_strings: Sequence[str],
328 default: _T | str | None = ...,
329 type: Callable[[str], _T] | Callable[[str], _T] | FileType | None = ...,
330 choices: Iterable[_T] | None = ...,
331 required: bool = ...,
332 help: str | None = ...,
333 metavar: str | Tuple[str, ...] | None = ...,
336 class Namespace(_AttributeHolder):
337 def __init__(self, **kwargs: Any) -> None: ...
338 def __getattr__(self, name: str) -> Any: ...
339 def __setattr__(self, name: str, value: Any) -> None: ...
340 def __contains__(self, key: str) -> bool: ...
346 _encoding: str | None
348 def __init__(self, mode: str = ..., bufsize: int = ..., encoding: str | None = ..., errors: str | None = ...) -> None: ...
349 def __call__(self, string: str) -> IO[Any]: ...
352 class _ArgumentGroup(_ActionsContainer):
354 _group_actions: list[Action]
356 self, container: _ActionsContainer, title: str | None = ..., description: str | None = ..., **kwargs: Any
360 class _MutuallyExclusiveGroup(_ArgumentGroup):
362 _container: _ActionsContainer
363 def __init__(self, container: _ActionsContainer, required: bool = ...) -> None: ...
366 class _StoreAction(Action): ...
369 class _StoreConstAction(Action):
372 option_strings: Sequence[str],
376 required: bool = ...,
377 help: str | None = ...,
378 metavar: str | Tuple[str, ...] | None = ...,
382 class _StoreTrueAction(_StoreConstAction):
384 self, option_strings: Sequence[str], dest: str, default: bool = ..., required: bool = ..., help: str | None = ...
388 class _StoreFalseAction(_StoreConstAction):
390 self, option_strings: Sequence[str], dest: str, default: bool = ..., required: bool = ..., help: str | None = ...
394 class _AppendAction(Action): ...
397 class _AppendConstAction(Action):
400 option_strings: Sequence[str],
404 required: bool = ...,
405 help: str | None = ...,
406 metavar: str | Tuple[str, ...] | None = ...,
410 class _CountAction(Action):
412 self, option_strings: Sequence[str], dest: str, default: Any = ..., required: bool = ..., help: str | None = ...
416 class _HelpAction(Action):
417 def __init__(self, option_strings: Sequence[str], dest: str = ..., default: str = ..., help: str | None = ...) -> None: ...
420 class _VersionAction(Action):
423 self, option_strings: Sequence[str], version: str | None = ..., dest: str = ..., default: str = ..., help: str = ...
427 class _SubParsersAction(Action, Generic[_ArgumentParserT]):
428 _ChoicesPseudoAction: Type[Any] # nested class
430 _parser_class: Type[_ArgumentParserT]
431 _name_parser_map: dict[str, _ArgumentParserT]
432 choices: dict[str, _ArgumentParserT]
433 _choices_actions: list[Action]
434 if sys.version_info >= (3, 7):
437 option_strings: Sequence[str],
439 parser_class: Type[_ArgumentParserT],
441 required: bool = ...,
442 help: str | None = ...,
443 metavar: str | Tuple[str, ...] | None = ...,
448 option_strings: Sequence[str],
450 parser_class: Type[_ArgumentParserT],
452 help: str | None = ...,
453 metavar: str | Tuple[str, ...] | None = ...,
455 # TODO: Type keyword args properly.
456 def add_parser(self, name: str, **kwargs: Any) -> _ArgumentParserT: ...
457 def _get_subactions(self) -> list[Action]: ...
460 class ArgumentTypeError(Exception): ...
462 if sys.version_info < (3, 7):
464 def _ensure_value(namespace: Namespace, name: str, value: Any) -> Any: ...
467 def _get_action_name(argument: Action | None) -> str | None: ...