mirror of
https://github.com/davidhalter/typeshed.git
synced 2025-12-09 05:24:52 +08:00
Switch to PEP-604 syntax in python2 stubs (#5915)
Signed-off-by: oleg.hoefling <oleg.hoefling@gmail.com>
This commit is contained in:
@@ -7,7 +7,6 @@ from typing import (
|
||||
Iterable,
|
||||
List,
|
||||
NoReturn,
|
||||
Optional,
|
||||
Pattern,
|
||||
Protocol,
|
||||
Sequence,
|
||||
@@ -34,9 +33,9 @@ ZERO_OR_MORE: str
|
||||
_UNRECOGNIZED_ARGS_ATTR: str # undocumented
|
||||
|
||||
class ArgumentError(Exception):
|
||||
argument_name: Optional[str]
|
||||
argument_name: str | None
|
||||
message: str
|
||||
def __init__(self, argument: Optional[Action], message: str) -> None: ...
|
||||
def __init__(self, argument: Action | None, message: str) -> None: ...
|
||||
|
||||
# undocumented
|
||||
class _AttributeHolder:
|
||||
@@ -45,7 +44,7 @@ class _AttributeHolder:
|
||||
|
||||
# undocumented
|
||||
class _ActionsContainer:
|
||||
description: Optional[_Text]
|
||||
description: _Text | None
|
||||
prefix_chars: _Text
|
||||
argument_default: Any
|
||||
conflict_handler: _Text
|
||||
@@ -58,9 +57,7 @@ class _ActionsContainer:
|
||||
_defaults: Dict[str, Any]
|
||||
_negative_number_matcher: Pattern[str]
|
||||
_has_negative_number_optionals: List[bool]
|
||||
def __init__(
|
||||
self, description: Optional[Text], prefix_chars: Text, argument_default: Any, conflict_handler: Text
|
||||
) -> None: ...
|
||||
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: ...
|
||||
def set_defaults(self, **kwargs: Any) -> None: ...
|
||||
@@ -68,16 +65,16 @@ class _ActionsContainer:
|
||||
def add_argument(
|
||||
self,
|
||||
*name_or_flags: Text,
|
||||
action: Union[Text, Type[Action]] = ...,
|
||||
nargs: Union[int, Text] = ...,
|
||||
action: Text | Type[Action] = ...,
|
||||
nargs: int | Text = ...,
|
||||
const: Any = ...,
|
||||
default: Any = ...,
|
||||
type: Union[Callable[[Text], _T], Callable[[str], _T], FileType] = ...,
|
||||
type: Callable[[Text], _T] | Callable[[str], _T] | FileType = ...,
|
||||
choices: Iterable[_T] = ...,
|
||||
required: bool = ...,
|
||||
help: Optional[Text] = ...,
|
||||
metavar: Optional[Union[Text, Tuple[Text, ...]]] = ...,
|
||||
dest: Optional[Text] = ...,
|
||||
help: Text | None = ...,
|
||||
metavar: Text | Tuple[Text, ...] | None = ...,
|
||||
dest: Text | None = ...,
|
||||
version: Text = ...,
|
||||
**kwargs: Any,
|
||||
) -> Action: ...
|
||||
@@ -88,7 +85,7 @@ class _ActionsContainer:
|
||||
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: Optional[Type[Action]] = ...) -> Type[Action]: ...
|
||||
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: ...
|
||||
@@ -99,26 +96,26 @@ class _FormatterClass(Protocol):
|
||||
|
||||
class ArgumentParser(_AttributeHolder, _ActionsContainer):
|
||||
prog: _Text
|
||||
usage: Optional[_Text]
|
||||
epilog: Optional[_Text]
|
||||
usage: _Text | None
|
||||
epilog: _Text | None
|
||||
formatter_class: _FormatterClass
|
||||
fromfile_prefix_chars: Optional[_Text]
|
||||
fromfile_prefix_chars: _Text | None
|
||||
add_help: bool
|
||||
|
||||
# undocumented
|
||||
_positionals: _ArgumentGroup
|
||||
_optionals: _ArgumentGroup
|
||||
_subparsers: Optional[_ArgumentGroup]
|
||||
_subparsers: _ArgumentGroup | None
|
||||
def __init__(
|
||||
self,
|
||||
prog: Optional[Text] = ...,
|
||||
usage: Optional[Text] = ...,
|
||||
description: Optional[Text] = ...,
|
||||
epilog: Optional[Text] = ...,
|
||||
prog: Text | None = ...,
|
||||
usage: Text | None = ...,
|
||||
description: Text | None = ...,
|
||||
epilog: Text | None = ...,
|
||||
parents: Sequence[ArgumentParser] = ...,
|
||||
formatter_class: _FormatterClass = ...,
|
||||
prefix_chars: Text = ...,
|
||||
fromfile_prefix_chars: Optional[Text] = ...,
|
||||
fromfile_prefix_chars: Text | None = ...,
|
||||
argument_default: Any = ...,
|
||||
conflict_handler: Text = ...,
|
||||
add_help: bool = ...,
|
||||
@@ -126,11 +123,11 @@ class ArgumentParser(_AttributeHolder, _ActionsContainer):
|
||||
# The type-ignores in these overloads should be temporary. See:
|
||||
# https://github.com/python/typeshed/pull/2643#issuecomment-442280277
|
||||
@overload
|
||||
def parse_args(self, args: Optional[Sequence[Text]] = ...) -> Namespace: ...
|
||||
def parse_args(self, args: Sequence[Text] | None = ...) -> Namespace: ...
|
||||
@overload
|
||||
def parse_args(self, args: Optional[Sequence[Text]], namespace: None) -> Namespace: ... # type: ignore
|
||||
def parse_args(self, args: Sequence[Text] | None, namespace: None) -> Namespace: ... # type: ignore
|
||||
@overload
|
||||
def parse_args(self, args: Optional[Sequence[Text]], namespace: _N) -> _N: ...
|
||||
def parse_args(self, args: Sequence[Text] | None, namespace: _N) -> _N: ...
|
||||
@overload
|
||||
def parse_args(self, *, namespace: None) -> Namespace: ... # type: ignore
|
||||
@overload
|
||||
@@ -139,24 +136,24 @@ class ArgumentParser(_AttributeHolder, _ActionsContainer):
|
||||
self,
|
||||
*,
|
||||
title: Text = ...,
|
||||
description: Optional[Text] = ...,
|
||||
description: Text | None = ...,
|
||||
prog: Text = ...,
|
||||
parser_class: Type[ArgumentParser] = ...,
|
||||
action: Type[Action] = ...,
|
||||
option_string: Text = ...,
|
||||
dest: Optional[Text] = ...,
|
||||
help: Optional[Text] = ...,
|
||||
metavar: Optional[Text] = ...,
|
||||
dest: Text | None = ...,
|
||||
help: Text | None = ...,
|
||||
metavar: Text | None = ...,
|
||||
) -> _SubParsersAction: ...
|
||||
def print_usage(self, file: Optional[IO[str]] = ...) -> None: ...
|
||||
def print_help(self, file: Optional[IO[str]] = ...) -> None: ...
|
||||
def print_usage(self, file: IO[str] | None = ...) -> None: ...
|
||||
def print_help(self, file: IO[str] | None = ...) -> None: ...
|
||||
def format_usage(self) -> str: ...
|
||||
def format_help(self) -> str: ...
|
||||
def parse_known_args(
|
||||
self, args: Optional[Sequence[Text]] = ..., namespace: Optional[Namespace] = ...
|
||||
self, args: Sequence[Text] | None = ..., namespace: Namespace | None = ...
|
||||
) -> Tuple[Namespace, List[str]]: ...
|
||||
def convert_arg_line_to_args(self, arg_line: Text) -> List[str]: ...
|
||||
def exit(self, status: int = ..., message: Optional[Text] = ...) -> NoReturn: ...
|
||||
def exit(self, status: int = ..., message: Text | None = ...) -> NoReturn: ...
|
||||
def error(self, message: Text) -> NoReturn: ...
|
||||
# undocumented
|
||||
def _get_optional_actions(self) -> List[Action]: ...
|
||||
@@ -165,14 +162,14 @@ class ArgumentParser(_AttributeHolder, _ActionsContainer):
|
||||
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) -> Optional[Tuple[Optional[Action], Text, Optional[Text]]]: ...
|
||||
def _get_option_tuples(self, option_string: Text) -> List[Tuple[Action, Text, Optional[Text]]]: ...
|
||||
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_value(self, action: Action, arg_string: Text) -> Any: ...
|
||||
def _check_value(self, action: Action, value: Any) -> None: ...
|
||||
def _get_formatter(self) -> HelpFormatter: ...
|
||||
def _print_message(self, message: str, file: Optional[IO[str]] = ...) -> None: ...
|
||||
def _print_message(self, message: str, file: IO[str] | None = ...) -> None: ...
|
||||
|
||||
class HelpFormatter:
|
||||
# undocumented
|
||||
@@ -189,23 +186,23 @@ class HelpFormatter:
|
||||
_long_break_matcher: Pattern[str]
|
||||
_Section: Type[Any] # Nested class
|
||||
def __init__(
|
||||
self, prog: Text, indent_increment: int = ..., max_help_position: int = ..., width: Optional[int] = ...
|
||||
self, prog: Text, indent_increment: int = ..., max_help_position: int = ..., width: int | None = ...
|
||||
) -> None: ...
|
||||
def _indent(self) -> None: ...
|
||||
def _dedent(self) -> None: ...
|
||||
def _add_item(self, func: Callable[..., _Text], args: Iterable[Any]) -> None: ...
|
||||
def start_section(self, heading: Optional[Text]) -> None: ...
|
||||
def start_section(self, heading: Text | None) -> None: ...
|
||||
def end_section(self) -> None: ...
|
||||
def add_text(self, text: Optional[Text]) -> None: ...
|
||||
def add_text(self, text: Text | None) -> None: ...
|
||||
def add_usage(
|
||||
self, usage: Optional[Text], actions: Iterable[Action], groups: Iterable[_ArgumentGroup], prefix: Optional[Text] = ...
|
||||
self, usage: Text | None, actions: Iterable[Action], groups: Iterable[_ArgumentGroup], prefix: Text | None = ...
|
||||
) -> None: ...
|
||||
def add_argument(self, action: Action) -> None: ...
|
||||
def add_arguments(self, actions: Iterable[Action]) -> None: ...
|
||||
def format_help(self) -> _Text: ...
|
||||
def _join_parts(self, part_strings: Iterable[Text]) -> _Text: ...
|
||||
def _format_usage(
|
||||
self, usage: Text, actions: Iterable[Action], groups: Iterable[_ArgumentGroup], prefix: Optional[Text]
|
||||
self, usage: Text, actions: Iterable[Action], groups: Iterable[_ArgumentGroup], prefix: Text | None
|
||||
) -> _Text: ...
|
||||
def _format_actions_usage(self, actions: Iterable[Action], groups: Iterable[_ArgumentGroup]) -> _Text: ...
|
||||
def _format_text(self, text: Text) -> _Text: ...
|
||||
@@ -217,7 +214,7 @@ class HelpFormatter:
|
||||
def _iter_indented_subactions(self, action: Action) -> Generator[Action, None, None]: ...
|
||||
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) -> Optional[_Text]: ...
|
||||
def _get_help_string(self, action: Action) -> _Text | None: ...
|
||||
def _get_default_metavar_for_optional(self, action: Action) -> _Text: ...
|
||||
def _get_default_metavar_for_positional(self, action: Action) -> _Text: ...
|
||||
|
||||
@@ -228,33 +225,29 @@ class ArgumentDefaultsHelpFormatter(HelpFormatter): ...
|
||||
class Action(_AttributeHolder):
|
||||
option_strings: Sequence[_Text]
|
||||
dest: _Text
|
||||
nargs: Optional[Union[int, _Text]]
|
||||
nargs: int | _Text | None
|
||||
const: Any
|
||||
default: Any
|
||||
type: Union[Callable[[str], Any], FileType, None]
|
||||
choices: Optional[Iterable[Any]]
|
||||
type: Callable[[str], Any] | FileType | None
|
||||
choices: Iterable[Any] | None
|
||||
required: bool
|
||||
help: Optional[_Text]
|
||||
metavar: Optional[Union[_Text, Tuple[_Text, ...]]]
|
||||
help: _Text | None
|
||||
metavar: _Text | Tuple[_Text, ...] | None
|
||||
def __init__(
|
||||
self,
|
||||
option_strings: Sequence[Text],
|
||||
dest: Text,
|
||||
nargs: Optional[Union[int, Text]] = ...,
|
||||
const: Optional[_T] = ...,
|
||||
default: Union[_T, str, None] = ...,
|
||||
type: Optional[Union[Callable[[Text], _T], Callable[[str], _T], FileType]] = ...,
|
||||
choices: Optional[Iterable[_T]] = ...,
|
||||
nargs: int | Text | None = ...,
|
||||
const: _T | None = ...,
|
||||
default: _T | str | None = ...,
|
||||
type: Callable[[Text], _T] | Callable[[str], _T] | FileType | None = ...,
|
||||
choices: Iterable[_T] | None = ...,
|
||||
required: bool = ...,
|
||||
help: Optional[Text] = ...,
|
||||
metavar: Optional[Union[Text, Tuple[Text, ...]]] = ...,
|
||||
help: Text | None = ...,
|
||||
metavar: Text | Tuple[Text, ...] | None = ...,
|
||||
) -> None: ...
|
||||
def __call__(
|
||||
self,
|
||||
parser: ArgumentParser,
|
||||
namespace: Namespace,
|
||||
values: Union[Text, Sequence[Any], None],
|
||||
option_string: Optional[Text] = ...,
|
||||
self, parser: ArgumentParser, namespace: Namespace, values: Text | Sequence[Any] | None, option_string: Text | None = ...
|
||||
) -> None: ...
|
||||
|
||||
class Namespace(_AttributeHolder):
|
||||
@@ -267,15 +260,15 @@ class FileType:
|
||||
# undocumented
|
||||
_mode: _Text
|
||||
_bufsize: int
|
||||
def __init__(self, mode: Text = ..., bufsize: Optional[int] = ...) -> None: ...
|
||||
def __init__(self, mode: Text = ..., bufsize: int | None = ...) -> None: ...
|
||||
def __call__(self, string: Text) -> IO[Any]: ...
|
||||
|
||||
# undocumented
|
||||
class _ArgumentGroup(_ActionsContainer):
|
||||
title: Optional[_Text]
|
||||
title: _Text | None
|
||||
_group_actions: List[Action]
|
||||
def __init__(
|
||||
self, container: _ActionsContainer, title: Optional[Text] = ..., description: Optional[Text] = ..., **kwargs: Any
|
||||
self, container: _ActionsContainer, title: Text | None = ..., description: Text | None = ..., **kwargs: Any
|
||||
) -> None: ...
|
||||
|
||||
# undocumented
|
||||
@@ -296,20 +289,20 @@ class _StoreConstAction(Action):
|
||||
const: Any,
|
||||
default: Any = ...,
|
||||
required: bool = ...,
|
||||
help: Optional[Text] = ...,
|
||||
metavar: Optional[Union[Text, Tuple[Text, ...]]] = ...,
|
||||
help: Text | None = ...,
|
||||
metavar: Text | Tuple[Text, ...] | None = ...,
|
||||
) -> None: ...
|
||||
|
||||
# undocumented
|
||||
class _StoreTrueAction(_StoreConstAction):
|
||||
def __init__(
|
||||
self, option_strings: Sequence[Text], dest: Text, default: bool = ..., required: bool = ..., help: Optional[Text] = ...
|
||||
self, option_strings: Sequence[Text], dest: Text, default: bool = ..., required: bool = ..., help: Text | None = ...
|
||||
) -> None: ...
|
||||
|
||||
# undocumented
|
||||
class _StoreFalseAction(_StoreConstAction):
|
||||
def __init__(
|
||||
self, option_strings: Sequence[Text], dest: Text, default: bool = ..., required: bool = ..., help: Optional[Text] = ...
|
||||
self, option_strings: Sequence[Text], dest: Text, default: bool = ..., required: bool = ..., help: Text | None = ...
|
||||
) -> None: ...
|
||||
|
||||
# undocumented
|
||||
@@ -324,32 +317,27 @@ class _AppendConstAction(Action):
|
||||
const: Any,
|
||||
default: Any = ...,
|
||||
required: bool = ...,
|
||||
help: Optional[Text] = ...,
|
||||
metavar: Optional[Union[Text, Tuple[Text, ...]]] = ...,
|
||||
help: Text | None = ...,
|
||||
metavar: Text | Tuple[Text, ...] | None = ...,
|
||||
) -> None: ...
|
||||
|
||||
# undocumented
|
||||
class _CountAction(Action):
|
||||
def __init__(
|
||||
self, option_strings: Sequence[Text], dest: Text, default: Any = ..., required: bool = ..., help: Optional[Text] = ...
|
||||
self, option_strings: Sequence[Text], dest: Text, default: Any = ..., required: bool = ..., help: Text | None = ...
|
||||
) -> None: ...
|
||||
|
||||
# undocumented
|
||||
class _HelpAction(Action):
|
||||
def __init__(
|
||||
self, option_strings: Sequence[Text], dest: Text = ..., default: Text = ..., help: Optional[Text] = ...
|
||||
self, option_strings: Sequence[Text], dest: Text = ..., default: Text = ..., help: Text | None = ...
|
||||
) -> None: ...
|
||||
|
||||
# undocumented
|
||||
class _VersionAction(Action):
|
||||
version: Optional[_Text]
|
||||
version: _Text | None
|
||||
def __init__(
|
||||
self,
|
||||
option_strings: Sequence[Text],
|
||||
version: Optional[Text] = ...,
|
||||
dest: Text = ...,
|
||||
default: Text = ...,
|
||||
help: Text = ...,
|
||||
self, option_strings: Sequence[Text], version: Text | None = ..., dest: Text = ..., default: Text = ..., help: Text = ...
|
||||
) -> None: ...
|
||||
|
||||
# undocumented
|
||||
@@ -366,8 +354,8 @@ class _SubParsersAction(Action):
|
||||
prog: Text,
|
||||
parser_class: Type[ArgumentParser],
|
||||
dest: Text = ...,
|
||||
help: Optional[Text] = ...,
|
||||
metavar: Optional[Union[Text, Tuple[Text, ...]]] = ...,
|
||||
help: Text | None = ...,
|
||||
metavar: Text | Tuple[Text, ...] | None = ...,
|
||||
) -> None: ...
|
||||
# TODO: Type keyword args properly.
|
||||
def add_parser(self, name: Text, **kwargs: Any) -> ArgumentParser: ...
|
||||
@@ -380,4 +368,4 @@ class ArgumentTypeError(Exception): ...
|
||||
def _ensure_value(namespace: Namespace, name: Text, value: Any) -> Any: ...
|
||||
|
||||
# undocumented
|
||||
def _get_action_name(argument: Optional[Action]) -> Optional[str]: ...
|
||||
def _get_action_name(argument: Action | None) -> str | None: ...
|
||||
|
||||
Reference in New Issue
Block a user