Use PEP 585 syntax in Python 2, protobuf & _ast stubs, where possible (#6949)

This commit is contained in:
Alex Waygood
2022-01-18 15:14:03 +00:00
committed by GitHub
parent aa885ecd65
commit 8af5e0d340
264 changed files with 2217 additions and 2411 deletions

View File

@@ -1,22 +1,4 @@
from typing import (
IO,
Any,
Callable,
Dict,
Generator,
Iterable,
List,
NoReturn,
Pattern,
Protocol,
Sequence,
Text,
Tuple,
Type,
TypeVar,
Union,
overload,
)
from typing import IO, Any, Callable, Generator, Iterable, NoReturn, Pattern, Protocol, Sequence, Text, TypeVar, Union, overload
_T = TypeVar("_T")
_ActionT = TypeVar("_ActionT", bound=Action)
@@ -39,8 +21,8 @@ class ArgumentError(Exception):
# undocumented
class _AttributeHolder:
def _get_kwargs(self) -> List[Tuple[str, Any]]: ...
def _get_args(self) -> List[Any]: ...
def _get_kwargs(self) -> list[tuple[str, Any]]: ...
def _get_args(self) -> list[Any]: ...
# undocumented
class _ActionsContainer:
@@ -49,14 +31,14 @@ class _ActionsContainer:
argument_default: Any
conflict_handler: _Text
_registries: Dict[_Text, Dict[Any, Any]]
_actions: List[Action]
_option_string_actions: Dict[_Text, Action]
_action_groups: List[_ArgumentGroup]
_mutually_exclusive_groups: List[_MutuallyExclusiveGroup]
_defaults: Dict[str, Any]
_registries: dict[_Text, dict[Any, Any]]
_actions: list[Action]
_option_string_actions: dict[_Text, Action]
_action_groups: list[_ArgumentGroup]
_mutually_exclusive_groups: list[_MutuallyExclusiveGroup]
_defaults: dict[str, Any]
_negative_number_matcher: Pattern[str]
_has_negative_number_optionals: List[bool]
_has_negative_number_optionals: list[bool]
def __init__(self, description: Text | None, prefix_chars: Text, argument_default: Any, conflict_handler: Text) -> None: ...
def register(self, registry_name: Text, value: Any, object: Any) -> None: ...
def _registry_get(self, registry_name: Text, value: Any, default: Any = ...) -> Any: ...
@@ -65,7 +47,7 @@ class _ActionsContainer:
def add_argument(
self,
*name_or_flags: Text,
action: Text | Type[Action] = ...,
action: Text | type[Action] = ...,
nargs: int | Text = ...,
const: Any = ...,
default: Any = ...,
@@ -73,7 +55,7 @@ class _ActionsContainer:
choices: Iterable[_T] = ...,
required: bool = ...,
help: Text | None = ...,
metavar: Text | Tuple[Text, ...] | None = ...,
metavar: Text | tuple[Text, ...] | None = ...,
dest: Text | None = ...,
version: Text = ...,
**kwargs: Any,
@@ -83,13 +65,13 @@ class _ActionsContainer:
def _add_action(self, action: _ActionT) -> _ActionT: ...
def _remove_action(self, action: Action) -> None: ...
def _add_container_actions(self, container: _ActionsContainer) -> None: ...
def _get_positional_kwargs(self, dest: Text, **kwargs: Any) -> Dict[str, Any]: ...
def _get_optional_kwargs(self, *args: Any, **kwargs: Any) -> Dict[str, Any]: ...
def _pop_action_class(self, kwargs: Any, default: Type[Action] | None = ...) -> Type[Action]: ...
def _get_handler(self) -> Callable[[Action, Iterable[Tuple[Text, Action]]], Any]: ...
def _get_positional_kwargs(self, dest: Text, **kwargs: Any) -> dict[str, Any]: ...
def _get_optional_kwargs(self, *args: Any, **kwargs: Any) -> dict[str, Any]: ...
def _pop_action_class(self, kwargs: Any, default: type[Action] | None = ...) -> type[Action]: ...
def _get_handler(self) -> Callable[[Action, Iterable[tuple[Text, Action]]], Any]: ...
def _check_conflict(self, action: Action) -> None: ...
def _handle_conflict_error(self, action: Action, conflicting_actions: Iterable[Tuple[Text, Action]]) -> NoReturn: ...
def _handle_conflict_resolve(self, action: Action, conflicting_actions: Iterable[Tuple[Text, Action]]) -> None: ...
def _handle_conflict_error(self, action: Action, conflicting_actions: Iterable[tuple[Text, Action]]) -> NoReturn: ...
def _handle_conflict_resolve(self, action: Action, conflicting_actions: Iterable[tuple[Text, Action]]) -> None: ...
class _FormatterClass(Protocol):
def __call__(self, prog: str) -> HelpFormatter: ...
@@ -138,8 +120,8 @@ class ArgumentParser(_AttributeHolder, _ActionsContainer):
title: Text = ...,
description: Text | None = ...,
prog: Text = ...,
parser_class: Type[ArgumentParser] = ...,
action: Type[Action] = ...,
parser_class: type[ArgumentParser] = ...,
action: type[Action] = ...,
option_string: Text = ...,
dest: Text | None = ...,
help: Text | None = ...,
@@ -151,21 +133,21 @@ class ArgumentParser(_AttributeHolder, _ActionsContainer):
def format_help(self) -> str: ...
def parse_known_args(
self, args: Sequence[Text] | None = ..., namespace: Namespace | None = ...
) -> Tuple[Namespace, List[str]]: ...
def convert_arg_line_to_args(self, arg_line: Text) -> List[str]: ...
) -> tuple[Namespace, list[str]]: ...
def convert_arg_line_to_args(self, arg_line: Text) -> list[str]: ...
def exit(self, status: int = ..., message: Text | None = ...) -> NoReturn: ...
def error(self, message: Text) -> NoReturn: ...
# undocumented
def _get_optional_actions(self) -> List[Action]: ...
def _get_positional_actions(self) -> List[Action]: ...
def _parse_known_args(self, arg_strings: List[Text], namespace: Namespace) -> Tuple[Namespace, List[str]]: ...
def _read_args_from_files(self, arg_strings: List[Text]) -> List[Text]: ...
def _get_optional_actions(self) -> list[Action]: ...
def _get_positional_actions(self) -> list[Action]: ...
def _parse_known_args(self, arg_strings: list[Text], namespace: Namespace) -> tuple[Namespace, list[str]]: ...
def _read_args_from_files(self, arg_strings: list[Text]) -> list[Text]: ...
def _match_argument(self, action: Action, arg_strings_pattern: Text) -> int: ...
def _match_arguments_partial(self, actions: Sequence[Action], arg_strings_pattern: Text) -> List[int]: ...
def _parse_optional(self, arg_string: Text) -> Tuple[Action | None, Text, Text | None] | None: ...
def _get_option_tuples(self, option_string: Text) -> List[Tuple[Action, Text, Text | None]]: ...
def _match_arguments_partial(self, actions: Sequence[Action], arg_strings_pattern: Text) -> list[int]: ...
def _parse_optional(self, arg_string: Text) -> tuple[Action | None, Text, Text | None] | None: ...
def _get_option_tuples(self, option_string: Text) -> list[tuple[Action, Text, Text | None]]: ...
def _get_nargs_pattern(self, action: Action) -> _Text: ...
def _get_values(self, action: Action, arg_strings: List[Text]) -> Any: ...
def _get_values(self, action: Action, arg_strings: list[Text]) -> Any: ...
def _get_value(self, action: Action, arg_string: Text) -> Any: ...
def _check_value(self, action: Action, value: Any) -> None: ...
def _get_formatter(self) -> HelpFormatter: ...
@@ -184,7 +166,7 @@ class HelpFormatter:
_current_section: Any
_whitespace_matcher: Pattern[str]
_long_break_matcher: Pattern[str]
_Section: Type[Any] # Nested class
_Section: type[Any] # Nested class
def __init__(
self, prog: Text, indent_increment: int = ..., max_help_position: int = ..., width: int | None = ...
) -> None: ...
@@ -208,11 +190,11 @@ class HelpFormatter:
def _format_text(self, text: Text) -> _Text: ...
def _format_action(self, action: Action) -> _Text: ...
def _format_action_invocation(self, action: Action) -> _Text: ...
def _metavar_formatter(self, action: Action, default_metavar: Text) -> Callable[[int], Tuple[_Text, ...]]: ...
def _metavar_formatter(self, action: Action, default_metavar: Text) -> Callable[[int], tuple[_Text, ...]]: ...
def _format_args(self, action: Action, default_metavar: Text) -> _Text: ...
def _expand_help(self, action: Action) -> _Text: ...
def _iter_indented_subactions(self, action: Action) -> Generator[Action, None, None]: ...
def _split_lines(self, text: Text, width: int) -> List[_Text]: ...
def _split_lines(self, text: Text, width: int) -> list[_Text]: ...
def _fill_text(self, text: Text, width: int, indent: Text) -> _Text: ...
def _get_help_string(self, action: Action) -> _Text | None: ...
def _get_default_metavar_for_optional(self, action: Action) -> _Text: ...
@@ -232,7 +214,7 @@ class Action(_AttributeHolder):
choices: Iterable[Any] | None
required: bool
help: _Text | None
metavar: _Text | Tuple[_Text, ...] | None
metavar: _Text | tuple[_Text, ...] | None
def __init__(
self,
option_strings: Sequence[Text],
@@ -244,7 +226,7 @@ class Action(_AttributeHolder):
choices: Iterable[_T] | None = ...,
required: bool = ...,
help: Text | None = ...,
metavar: Text | Tuple[Text, ...] | None = ...,
metavar: Text | tuple[Text, ...] | None = ...,
) -> None: ...
def __call__(
self, parser: ArgumentParser, namespace: Namespace, values: Text | Sequence[Any] | None, option_string: Text | None = ...
@@ -266,7 +248,7 @@ class FileType:
# undocumented
class _ArgumentGroup(_ActionsContainer):
title: _Text | None
_group_actions: List[Action]
_group_actions: list[Action]
def __init__(
self, container: _ActionsContainer, title: Text | None = ..., description: Text | None = ..., **kwargs: Any
) -> None: ...
@@ -290,7 +272,7 @@ class _StoreConstAction(Action):
default: Any = ...,
required: bool = ...,
help: Text | None = ...,
metavar: Text | Tuple[Text, ...] | None = ...,
metavar: Text | tuple[Text, ...] | None = ...,
) -> None: ...
# undocumented
@@ -318,7 +300,7 @@ class _AppendConstAction(Action):
default: Any = ...,
required: bool = ...,
help: Text | None = ...,
metavar: Text | Tuple[Text, ...] | None = ...,
metavar: Text | tuple[Text, ...] | None = ...,
) -> None: ...
# undocumented
@@ -342,24 +324,24 @@ class _VersionAction(Action):
# undocumented
class _SubParsersAction(Action):
_ChoicesPseudoAction: Type[Any] # nested class
_ChoicesPseudoAction: type[Any] # nested class
_prog_prefix: _Text
_parser_class: Type[ArgumentParser]
_name_parser_map: Dict[_Text, ArgumentParser]
choices: Dict[_Text, ArgumentParser]
_choices_actions: List[Action]
_parser_class: type[ArgumentParser]
_name_parser_map: dict[_Text, ArgumentParser]
choices: dict[_Text, ArgumentParser]
_choices_actions: list[Action]
def __init__(
self,
option_strings: Sequence[Text],
prog: Text,
parser_class: Type[ArgumentParser],
parser_class: type[ArgumentParser],
dest: Text = ...,
help: Text | None = ...,
metavar: Text | Tuple[Text, ...] | None = ...,
metavar: Text | tuple[Text, ...] | None = ...,
) -> None: ...
# TODO: Type keyword args properly.
def add_parser(self, name: Text, **kwargs: Any) -> ArgumentParser: ...
def _get_subactions(self) -> List[Action]: ...
def _get_subactions(self) -> list[Action]: ...
# undocumented
class ArgumentTypeError(Exception): ...