Format: application/octet-stream
⬇ Download File (17.9 KB)
   1  import sys
   2  from typing import (
   3      IO,
   4      Any,
   5      Callable,
   6      Dict,
   7      Generator,
   8      Iterable,
   9      List,
  10      NoReturn,
  11      Optional,
  12      Pattern,
  13      Protocol,
  14      Sequence,
  15      Text,
  16      Tuple,
  17      Type,
  18      TypeVar,
  19      Union,
  20      overload,
  21  )
  22  
  23  _T = TypeVar("_T")
  24  _ActionT = TypeVar("_ActionT", bound=Action)
  25  _N = TypeVar("_N")
  26  
  27  if sys.version_info >= (3,):
  28      _Text = str
  29  else:
  30      _Text = Union[str, unicode]
  31  
  32  ONE_OR_MORE: str
  33  OPTIONAL: str
  34  PARSER: str
  35  REMAINDER: str
  36  SUPPRESS: str
  37  ZERO_OR_MORE: str
  38  _UNRECOGNIZED_ARGS_ATTR: str  # undocumented
  39  
  40  class ArgumentError(Exception):
  41      argument_name: Optional[str]
  42      message: str
  43      def __init__(self, argument: Optional[Action], message: str) -> None: ...
  44  
  45  # undocumented
  46  class _AttributeHolder:
  47      def _get_kwargs(self) -> List[Tuple[str, Any]]: ...
  48      def _get_args(self) -> List[Any]: ...
  49  
  50  # undocumented
  51  class _ActionsContainer:
  52      description: Optional[_Text]
  53      prefix_chars: _Text
  54      argument_default: Any
  55      conflict_handler: _Text
  56  
  57      _registries: Dict[_Text, Dict[Any, Any]]
  58      _actions: List[Action]
  59      _option_string_actions: Dict[_Text, Action]
  60      _action_groups: List[_ArgumentGroup]
  61      _mutually_exclusive_groups: List[_MutuallyExclusiveGroup]
  62      _defaults: Dict[str, Any]
  63      _negative_number_matcher: Pattern[str]
  64      _has_negative_number_optionals: List[bool]
  65      def __init__(
  66          self, description: Optional[Text], prefix_chars: Text, argument_default: Any, conflict_handler: Text
  67      ) -> None: ...
  68      def register(self, registry_name: Text, value: Any, object: Any) -> None: ...
  69      def _registry_get(self, registry_name: Text, value: Any, default: Any = ...) -> Any: ...
  70      def set_defaults(self, **kwargs: Any) -> None: ...
  71      def get_default(self, dest: Text) -> Any: ...
  72      def add_argument(
  73          self,
  74          *name_or_flags: Text,
  75          action: Union[Text, Type[Action]] = ...,
  76          nargs: Union[int, Text] = ...,
  77          const: Any = ...,
  78          default: Any = ...,
  79          type: Union[Callable[[Text], _T], Callable[[str], _T], FileType] = ...,
  80          choices: Iterable[_T] = ...,
  81          required: bool = ...,
  82          help: Optional[Text] = ...,
  83          metavar: Optional[Union[Text, Tuple[Text, ...]]] = ...,
  84          dest: Optional[Text] = ...,
  85          version: Text = ...,
  86          **kwargs: Any,
  87      ) -> Action: ...
  88      def add_argument_group(self, *args: Any, **kwargs: Any) -> _ArgumentGroup: ...
  89      def add_mutually_exclusive_group(self, **kwargs: Any) -> _MutuallyExclusiveGroup: ...
  90      def _add_action(self, action: _ActionT) -> _ActionT: ...
  91      def _remove_action(self, action: Action) -> None: ...
  92      def _add_container_actions(self, container: _ActionsContainer) -> None: ...
  93      def _get_positional_kwargs(self, dest: Text, **kwargs: Any) -> Dict[str, Any]: ...
  94      def _get_optional_kwargs(self, *args: Any, **kwargs: Any) -> Dict[str, Any]: ...
  95      def _pop_action_class(self, kwargs: Any, default: Optional[Type[Action]] = ...) -> Type[Action]: ...
  96      def _get_handler(self) -> Callable[[Action, Iterable[Tuple[Text, Action]]], Any]: ...
  97      def _check_conflict(self, action: Action) -> None: ...
  98      def _handle_conflict_error(self, action: Action, conflicting_actions: Iterable[Tuple[Text, Action]]) -> NoReturn: ...
  99      def _handle_conflict_resolve(self, action: Action, conflicting_actions: Iterable[Tuple[Text, Action]]) -> None: ...
 100  
 101  class _FormatterClass(Protocol):
 102      def __call__(self, prog: str) -> HelpFormatter: ...
 103  
 104  class ArgumentParser(_AttributeHolder, _ActionsContainer):
 105      prog: _Text
 106      usage: Optional[_Text]
 107      epilog: Optional[_Text]
 108      formatter_class: _FormatterClass
 109      fromfile_prefix_chars: Optional[_Text]
 110      add_help: bool
 111  
 112      if sys.version_info >= (3, 5):
 113          allow_abbrev: bool
 114  
 115      # undocumented
 116      _positionals: _ArgumentGroup
 117      _optionals: _ArgumentGroup
 118      _subparsers: Optional[_ArgumentGroup]
 119  
 120      if sys.version_info >= (3, 9):
 121          def __init__(
 122              self,
 123              prog: Optional[str] = ...,
 124              usage: Optional[str] = ...,
 125              description: Optional[str] = ...,
 126              epilog: Optional[str] = ...,
 127              parents: Sequence[ArgumentParser] = ...,
 128              formatter_class: _FormatterClass = ...,
 129              prefix_chars: str = ...,
 130              fromfile_prefix_chars: Optional[str] = ...,
 131              argument_default: Any = ...,
 132              conflict_handler: str = ...,
 133              add_help: bool = ...,
 134              allow_abbrev: bool = ...,
 135              exit_on_error: bool = ...,
 136          ) -> None: ...
 137      elif sys.version_info >= (3, 5):
 138          def __init__(
 139              self,
 140              prog: Optional[str] = ...,
 141              usage: Optional[str] = ...,
 142              description: Optional[str] = ...,
 143              epilog: Optional[str] = ...,
 144              parents: Sequence[ArgumentParser] = ...,
 145              formatter_class: _FormatterClass = ...,
 146              prefix_chars: str = ...,
 147              fromfile_prefix_chars: Optional[str] = ...,
 148              argument_default: Any = ...,
 149              conflict_handler: str = ...,
 150              add_help: bool = ...,
 151              allow_abbrev: bool = ...,
 152          ) -> None: ...
 153      else:
 154          def __init__(
 155              self,
 156              prog: Optional[Text] = ...,
 157              usage: Optional[Text] = ...,
 158              description: Optional[Text] = ...,
 159              epilog: Optional[Text] = ...,
 160              parents: Sequence[ArgumentParser] = ...,
 161              formatter_class: _FormatterClass = ...,
 162              prefix_chars: Text = ...,
 163              fromfile_prefix_chars: Optional[Text] = ...,
 164              argument_default: Any = ...,
 165              conflict_handler: Text = ...,
 166              add_help: bool = ...,
 167          ) -> None: ...
 168      # The type-ignores in these overloads should be temporary.  See:
 169      # https://github.com/python/typeshed/pull/2643#issuecomment-442280277
 170      @overload
 171      def parse_args(self, args: Optional[Sequence[Text]] = ...) -> Namespace: ...
 172      @overload
 173      def parse_args(self, args: Optional[Sequence[Text]], namespace: None) -> Namespace: ...  # type: ignore
 174      @overload
 175      def parse_args(self, args: Optional[Sequence[Text]], namespace: _N) -> _N: ...
 176      @overload
 177      def parse_args(self, *, namespace: None) -> Namespace: ...  # type: ignore
 178      @overload
 179      def parse_args(self, *, namespace: _N) -> _N: ...
 180      if sys.version_info >= (3, 7):
 181          def add_subparsers(
 182              self,
 183              *,
 184              title: str = ...,
 185              description: Optional[str] = ...,
 186              prog: str = ...,
 187              parser_class: Type[ArgumentParser] = ...,
 188              action: Type[Action] = ...,
 189              option_string: str = ...,
 190              dest: Optional[str] = ...,
 191              required: bool = ...,
 192              help: Optional[str] = ...,
 193              metavar: Optional[str] = ...,
 194          ) -> _SubParsersAction: ...
 195      else:
 196          def add_subparsers(
 197              self,
 198              *,
 199              title: Text = ...,
 200              description: Optional[Text] = ...,
 201              prog: Text = ...,
 202              parser_class: Type[ArgumentParser] = ...,
 203              action: Type[Action] = ...,
 204              option_string: Text = ...,
 205              dest: Optional[Text] = ...,
 206              help: Optional[Text] = ...,
 207              metavar: Optional[Text] = ...,
 208          ) -> _SubParsersAction: ...
 209      def print_usage(self, file: Optional[IO[str]] = ...) -> None: ...
 210      def print_help(self, file: Optional[IO[str]] = ...) -> None: ...
 211      def format_usage(self) -> str: ...
 212      def format_help(self) -> str: ...
 213      def parse_known_args(
 214          self, args: Optional[Sequence[Text]] = ..., namespace: Optional[Namespace] = ...
 215      ) -> Tuple[Namespace, List[str]]: ...
 216      def convert_arg_line_to_args(self, arg_line: Text) -> List[str]: ...
 217      def exit(self, status: int = ..., message: Optional[Text] = ...) -> NoReturn: ...
 218      def error(self, message: Text) -> NoReturn: ...
 219      if sys.version_info >= (3, 7):
 220          def parse_intermixed_args(
 221              self, args: Optional[Sequence[str]] = ..., namespace: Optional[Namespace] = ...
 222          ) -> Namespace: ...
 223          def parse_known_intermixed_args(
 224              self, args: Optional[Sequence[str]] = ..., namespace: Optional[Namespace] = ...
 225          ) -> Tuple[Namespace, List[str]]: ...
 226      # undocumented
 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[Text], namespace: Namespace) -> Tuple[Namespace, List[str]]: ...
 230      def _read_args_from_files(self, arg_strings: List[Text]) -> List[Text]: ...
 231      def _match_argument(self, action: Action, arg_strings_pattern: Text) -> int: ...
 232      def _match_arguments_partial(self, actions: Sequence[Action], arg_strings_pattern: Text) -> List[int]: ...
 233      def _parse_optional(self, arg_string: Text) -> Optional[Tuple[Optional[Action], Text, Optional[Text]]]: ...
 234      def _get_option_tuples(self, option_string: Text) -> List[Tuple[Action, Text, Optional[Text]]]: ...
 235      def _get_nargs_pattern(self, action: Action) -> _Text: ...
 236      def _get_values(self, action: Action, arg_strings: List[Text]) -> Any: ...
 237      def _get_value(self, action: Action, arg_string: Text) -> 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: Optional[IO[str]] = ...) -> None: ...
 241  
 242  class HelpFormatter:
 243      # undocumented
 244      _prog: _Text
 245      _indent_increment: int
 246      _max_help_position: int
 247      _width: int
 248      _current_indent: int
 249      _level: int
 250      _action_max_length: int
 251      _root_section: Any
 252      _current_section: Any
 253      _whitespace_matcher: Pattern[str]
 254      _long_break_matcher: Pattern[str]
 255      _Section: Type[Any]  # Nested class
 256      def __init__(
 257          self, prog: Text, indent_increment: int = ..., max_help_position: int = ..., width: Optional[int] = ...
 258      ) -> None: ...
 259      def _indent(self) -> None: ...
 260      def _dedent(self) -> None: ...
 261      def _add_item(self, func: Callable[..., _Text], args: Iterable[Any]) -> None: ...
 262      def start_section(self, heading: Optional[Text]) -> None: ...
 263      def end_section(self) -> None: ...
 264      def add_text(self, text: Optional[Text]) -> None: ...
 265      def add_usage(
 266          self, usage: Text, actions: Iterable[Action], groups: Iterable[_ArgumentGroup], prefix: Optional[Text] = ...
 267      ) -> None: ...
 268      def add_argument(self, action: Action) -> None: ...
 269      def add_arguments(self, actions: Iterable[Action]) -> None: ...
 270      def format_help(self) -> _Text: ...
 271      def _join_parts(self, part_strings: Iterable[Text]) -> _Text: ...
 272      def _format_usage(
 273          self, usage: Text, actions: Iterable[Action], groups: Iterable[_ArgumentGroup], prefix: Optional[Text]
 274      ) -> _Text: ...
 275      def _format_actions_usage(self, actions: Iterable[Action], groups: Iterable[_ArgumentGroup]) -> _Text: ...
 276      def _format_text(self, text: Text) -> _Text: ...
 277      def _format_action(self, action: Action) -> _Text: ...
 278      def _format_action_invocation(self, action: Action) -> _Text: ...
 279      def _metavar_formatter(self, action: Action, default_metavar: Text) -> Callable[[int], Tuple[_Text, ...]]: ...
 280      def _format_args(self, action: Action, default_metavar: Text) -> _Text: ...
 281      def _expand_help(self, action: Action) -> _Text: ...
 282      def _iter_indented_subactions(self, action: Action) -> Generator[Action, None, None]: ...
 283      def _split_lines(self, text: Text, width: int) -> List[_Text]: ...
 284      def _fill_text(self, text: Text, width: int, indent: Text) -> _Text: ...
 285      def _get_help_string(self, action: Action) -> Optional[_Text]: ...
 286      def _get_default_metavar_for_optional(self, action: Action) -> _Text: ...
 287      def _get_default_metavar_for_positional(self, action: Action) -> _Text: ...
 288  
 289  class RawDescriptionHelpFormatter(HelpFormatter): ...
 290  class RawTextHelpFormatter(RawDescriptionHelpFormatter): ...
 291  class ArgumentDefaultsHelpFormatter(HelpFormatter): ...
 292  
 293  if sys.version_info >= (3,):
 294      class MetavarTypeHelpFormatter(HelpFormatter): ...
 295  
 296  class Action(_AttributeHolder):
 297      option_strings: Sequence[_Text]
 298      dest: _Text
 299      nargs: Optional[Union[int, _Text]]
 300      const: Any
 301      default: Any
 302      type: Union[Callable[[str], Any], FileType, None]
 303      choices: Optional[Iterable[Any]]
 304      required: bool
 305      help: Optional[_Text]
 306      metavar: Optional[Union[_Text, Tuple[_Text, ...]]]
 307      def __init__(
 308          self,
 309          option_strings: Sequence[Text],
 310          dest: Text,
 311          nargs: Optional[Union[int, Text]] = ...,
 312          const: Optional[_T] = ...,
 313          default: Union[_T, str, None] = ...,
 314          type: Optional[Union[Callable[[Text], _T], Callable[[str], _T], FileType]] = ...,
 315          choices: Optional[Iterable[_T]] = ...,
 316          required: bool = ...,
 317          help: Optional[Text] = ...,
 318          metavar: Optional[Union[Text, Tuple[Text, ...]]] = ...,
 319      ) -> None: ...
 320      def __call__(
 321          self,
 322          parser: ArgumentParser,
 323          namespace: Namespace,
 324          values: Union[Text, Sequence[Any], None],
 325          option_string: Optional[Text] = ...,
 326      ) -> None: ...
 327      if sys.version_info >= (3, 9):
 328          def format_usage(self) -> str: ...
 329  
 330  if sys.version_info >= (3, 9):
 331      class BooleanOptionalAction(Action):
 332          def __init__(
 333              self,
 334              option_strings: Sequence[str],
 335              dest: str,
 336              default: Union[_T, str, None] = ...,
 337              type: Optional[Union[Callable[[Text], _T], Callable[[str], _T], FileType]] = ...,
 338              choices: Optional[Iterable[_T]] = ...,
 339              required: bool = ...,
 340              help: Optional[Text] = ...,
 341              metavar: Optional[Union[Text, Tuple[Text, ...]]] = ...,
 342          ) -> None: ...
 343  
 344  class Namespace(_AttributeHolder):
 345      def __init__(self, **kwargs: Any) -> None: ...
 346      def __getattr__(self, name: Text) -> Any: ...
 347      def __setattr__(self, name: Text, value: Any) -> None: ...
 348      def __contains__(self, key: str) -> bool: ...
 349  
 350  class FileType:
 351      # undocumented
 352      _mode: _Text
 353      _bufsize: int
 354      if sys.version_info >= (3,):
 355          _encoding: Optional[str]
 356          _errors: Optional[str]
 357          def __init__(
 358              self, mode: str = ..., bufsize: int = ..., encoding: Optional[str] = ..., errors: Optional[str] = ...
 359          ) -> None: ...
 360      else:
 361          def __init__(self, mode: Text = ..., bufsize: Optional[int] = ...) -> None: ...
 362      def __call__(self, string: Text) -> IO[Any]: ...
 363  
 364  # undocumented
 365  class _ArgumentGroup(_ActionsContainer):
 366      title: Optional[_Text]
 367      _group_actions: List[Action]
 368      def __init__(
 369          self, container: _ActionsContainer, title: Optional[Text] = ..., description: Optional[Text] = ..., **kwargs: Any
 370      ) -> None: ...
 371  
 372  # undocumented
 373  class _MutuallyExclusiveGroup(_ArgumentGroup):
 374      required: bool
 375      _container: _ActionsContainer
 376      def __init__(self, container: _ActionsContainer, required: bool = ...) -> None: ...
 377  
 378  # undocumented
 379  class _StoreAction(Action): ...
 380  
 381  # undocumented
 382  class _StoreConstAction(Action):
 383      def __init__(
 384          self,
 385          option_strings: Sequence[Text],
 386          dest: Text,
 387          const: Any,
 388          default: Any = ...,
 389          required: bool = ...,
 390          help: Optional[Text] = ...,
 391          metavar: Optional[Union[Text, Tuple[Text, ...]]] = ...,
 392      ) -> None: ...
 393  
 394  # undocumented
 395  class _StoreTrueAction(_StoreConstAction):
 396      def __init__(
 397          self, option_strings: Sequence[Text], dest: Text, default: bool = ..., required: bool = ..., help: Optional[Text] = ...
 398      ) -> None: ...
 399  
 400  # undocumented
 401  class _StoreFalseAction(_StoreConstAction):
 402      def __init__(
 403          self, option_strings: Sequence[Text], dest: Text, default: bool = ..., required: bool = ..., help: Optional[Text] = ...
 404      ) -> None: ...
 405  
 406  # undocumented
 407  class _AppendAction(Action): ...
 408  
 409  # undocumented
 410  class _AppendConstAction(Action):
 411      def __init__(
 412          self,
 413          option_strings: Sequence[Text],
 414          dest: Text,
 415          const: Any,
 416          default: Any = ...,
 417          required: bool = ...,
 418          help: Optional[Text] = ...,
 419          metavar: Optional[Union[Text, Tuple[Text, ...]]] = ...,
 420      ) -> None: ...
 421  
 422  # undocumented
 423  class _CountAction(Action):
 424      def __init__(
 425          self, option_strings: Sequence[Text], dest: Text, default: Any = ..., required: bool = ..., help: Optional[Text] = ...
 426      ) -> None: ...
 427  
 428  # undocumented
 429  class _HelpAction(Action):
 430      def __init__(
 431          self, option_strings: Sequence[Text], dest: Text = ..., default: Text = ..., help: Optional[Text] = ...
 432      ) -> None: ...
 433  
 434  # undocumented
 435  class _VersionAction(Action):
 436      version: Optional[_Text]
 437      def __init__(
 438          self,
 439          option_strings: Sequence[Text],
 440          version: Optional[Text] = ...,
 441          dest: Text = ...,
 442          default: Text = ...,
 443          help: Text = ...,
 444      ) -> None: ...
 445  
 446  # undocumented
 447  class _SubParsersAction(Action):
 448      _ChoicesPseudoAction: Type[Any]  # nested class
 449      _prog_prefix: _Text
 450      _parser_class: Type[ArgumentParser]
 451      _name_parser_map: Dict[_Text, ArgumentParser]
 452      choices: Dict[_Text, ArgumentParser]
 453      _choices_actions: List[Action]
 454      if sys.version_info >= (3, 7):
 455          def __init__(
 456              self,
 457              option_strings: Sequence[Text],
 458              prog: Text,
 459              parser_class: Type[ArgumentParser],
 460              dest: Text = ...,
 461              required: bool = ...,
 462              help: Optional[Text] = ...,
 463              metavar: Optional[Union[Text, Tuple[Text, ...]]] = ...,
 464          ) -> None: ...
 465      else:
 466          def __init__(
 467              self,
 468              option_strings: Sequence[Text],
 469              prog: Text,
 470              parser_class: Type[ArgumentParser],
 471              dest: Text = ...,
 472              help: Optional[Text] = ...,
 473              metavar: Optional[Union[Text, Tuple[Text, ...]]] = ...,
 474          ) -> None: ...
 475      # TODO: Type keyword args properly.
 476      def add_parser(self, name: Text, **kwargs: Any) -> ArgumentParser: ...
 477      def _get_subactions(self) -> List[Action]: ...
 478  
 479  # undocumented
 480  class ArgumentTypeError(Exception): ...
 481  
 482  if sys.version_info < (3, 7):
 483      # undocumented
 484      def _ensure_value(namespace: Namespace, name: Text, value: Any) -> Any: ...
 485  
 486  # undocumented
 487  def _get_action_name(argument: Optional[Action]) -> Optional[str]: ...
 488