diff --git a/stdlib/_codecs.pyi b/stdlib/_codecs.pyi index 083852131..9d420af89 100644 --- a/stdlib/_codecs.pyi +++ b/stdlib/_codecs.pyi @@ -1,72 +1,68 @@ import codecs import sys -from typing import Any, Callable, Dict, Optional, Text, Tuple, Union - -# For convenience: -_Handler = Callable[[Exception], Tuple[Text, int]] -_String = Union[bytes, str] -_Errors = Union[str, Text, None] -_Decodable = bytes -_Encodable = str +from typing import Any, Callable, Dict, Optional, Tuple, Union # This type is not exposed; it is defined in unicodeobject.c -class _EncodingMap(object): +class _EncodingMap: def size(self) -> int: ... _MapT = Union[Dict[int, int], _EncodingMap] +_Handler = Callable[[Exception], Tuple[str, int]] def register(__search_function: Callable[[str], Any]) -> None: ... -def register_error(__errors: Union[str, Text], __handler: _Handler) -> None: ... -def lookup(__encoding: Union[str, Text]) -> codecs.CodecInfo: ... -def lookup_error(__name: Union[str, Text]) -> _Handler: ... -def decode(obj: Any, encoding: Union[str, Text] = ..., errors: _Errors = ...) -> Any: ... -def encode(obj: Any, encoding: Union[str, Text] = ..., errors: _Errors = ...) -> Any: ... -def charmap_build(__map: Text) -> _MapT: ... -def ascii_decode(__data: _Decodable, __errors: _Errors = ...) -> Tuple[Text, int]: ... -def ascii_encode(__str: _Encodable, __errors: _Errors = ...) -> Tuple[bytes, int]: ... -def charmap_decode(__data: _Decodable, __errors: _Errors = ..., __mapping: Optional[_MapT] = ...) -> Tuple[Text, int]: ... -def charmap_encode(__str: _Encodable, __errors: _Errors = ..., __mapping: Optional[_MapT] = ...) -> Tuple[bytes, int]: ... -def escape_decode(__data: _String, __errors: _Errors = ...) -> Tuple[str, int]: ... -def escape_encode(__data: bytes, __errors: _Errors = ...) -> Tuple[bytes, int]: ... -def latin_1_decode(__data: _Decodable, __errors: _Errors = ...) -> Tuple[Text, int]: ... -def latin_1_encode(__str: _Encodable, __errors: _Errors = ...) -> Tuple[bytes, int]: ... -def raw_unicode_escape_decode(__data: _String, __errors: _Errors = ...) -> Tuple[Text, int]: ... -def raw_unicode_escape_encode(__str: _Encodable, __errors: _Errors = ...) -> Tuple[bytes, int]: ... -def readbuffer_encode(__data: _String, __errors: _Errors = ...) -> Tuple[bytes, int]: ... -def unicode_escape_decode(__data: _String, __errors: _Errors = ...) -> Tuple[Text, int]: ... -def unicode_escape_encode(__str: _Encodable, __errors: _Errors = ...) -> Tuple[bytes, int]: ... +def register_error(__errors: str, __handler: _Handler) -> None: ... +def lookup(__encoding: str) -> codecs.CodecInfo: ... +def lookup_error(__name: str) -> _Handler: ... +def decode(obj: Any, encoding: str = ..., errors: Optional[str] = ...) -> Any: ... +def encode(obj: Any, encoding: str = ..., errors: Optional[str] = ...) -> Any: ... +def charmap_build(__map: str) -> _MapT: ... +def ascii_decode(__data: bytes, __errors: Optional[str] = ...) -> Tuple[str, int]: ... +def ascii_encode(__str: str, __errors: Optional[str] = ...) -> Tuple[bytes, int]: ... +def charmap_decode(__data: bytes, __errors: Optional[str] = ..., __mapping: Optional[_MapT] = ...) -> Tuple[str, int]: ... +def charmap_encode(__str: str, __errors: Optional[str] = ..., __mapping: Optional[_MapT] = ...) -> Tuple[bytes, int]: ... +def escape_decode(__data: Union[str, bytes], __errors: Optional[str] = ...) -> Tuple[str, int]: ... +def escape_encode(__data: bytes, __errors: Optional[str] = ...) -> Tuple[bytes, int]: ... +def latin_1_decode(__data: bytes, __errors: Optional[str] = ...) -> Tuple[str, int]: ... +def latin_1_encode(__str: str, __errors: Optional[str] = ...) -> Tuple[bytes, int]: ... +def raw_unicode_escape_decode(__data: Union[str, bytes], __errors: Optional[str] = ...) -> Tuple[str, int]: ... +def raw_unicode_escape_encode(__str: str, __errors: Optional[str] = ...) -> Tuple[bytes, int]: ... +def readbuffer_encode(__data: Union[str, bytes], __errors: Optional[str] = ...) -> Tuple[bytes, int]: ... +def unicode_escape_decode(__data: Union[str, bytes], __errors: Optional[str] = ...) -> Tuple[str, int]: ... +def unicode_escape_encode(__str: str, __errors: Optional[str] = ...) -> Tuple[bytes, int]: ... if sys.version_info < (3, 8): - def unicode_internal_decode(__obj: _String, __errors: _Errors = ...) -> Tuple[Text, int]: ... - def unicode_internal_encode(__obj: _String, __errors: _Errors = ...) -> Tuple[bytes, int]: ... + def unicode_internal_decode(__obj: Union[str, bytes], __errors: Optional[str] = ...) -> Tuple[str, int]: ... + def unicode_internal_encode(__obj: Union[str, bytes], __errors: Optional[str] = ...) -> Tuple[bytes, int]: ... -def utf_16_be_decode(__data: _Decodable, __errors: _Errors = ..., __final: int = ...) -> Tuple[Text, int]: ... -def utf_16_be_encode(__str: _Encodable, __errors: _Errors = ...) -> Tuple[bytes, int]: ... -def utf_16_decode(__data: _Decodable, __errors: _Errors = ..., __final: int = ...) -> Tuple[Text, int]: ... -def utf_16_encode(__str: _Encodable, __errors: _Errors = ..., __byteorder: int = ...) -> Tuple[bytes, int]: ... +def utf_16_be_decode(__data: bytes, __errors: Optional[str] = ..., __final: int = ...) -> Tuple[str, int]: ... +def utf_16_be_encode(__str: str, __errors: Optional[str] = ...) -> Tuple[bytes, int]: ... +def utf_16_decode(__data: bytes, __errors: Optional[str] = ..., __final: int = ...) -> Tuple[str, int]: ... +def utf_16_encode(__str: str, __errors: Optional[str] = ..., __byteorder: int = ...) -> Tuple[bytes, int]: ... def utf_16_ex_decode( - __data: _Decodable, __errors: _Errors = ..., __byteorder: int = ..., __final: int = ... -) -> Tuple[Text, int, int]: ... -def utf_16_le_decode(__data: _Decodable, __errors: _Errors = ..., __final: int = ...) -> Tuple[Text, int]: ... -def utf_16_le_encode(__str: _Encodable, __errors: _Errors = ...) -> Tuple[bytes, int]: ... -def utf_32_be_decode(__data: _Decodable, __errors: _Errors = ..., __final: int = ...) -> Tuple[Text, int]: ... -def utf_32_be_encode(__str: _Encodable, __errors: _Errors = ...) -> Tuple[bytes, int]: ... -def utf_32_decode(__data: _Decodable, __errors: _Errors = ..., __final: int = ...) -> Tuple[Text, int]: ... -def utf_32_encode(__str: _Encodable, __errors: _Errors = ..., __byteorder: int = ...) -> Tuple[bytes, int]: ... + __data: bytes, __errors: Optional[str] = ..., __byteorder: int = ..., __final: int = ... +) -> Tuple[str, int, int]: ... +def utf_16_le_decode(__data: bytes, __errors: Optional[str] = ..., __final: int = ...) -> Tuple[str, int]: ... +def utf_16_le_encode(__str: str, __errors: Optional[str] = ...) -> Tuple[bytes, int]: ... +def utf_32_be_decode(__data: bytes, __errors: Optional[str] = ..., __final: int = ...) -> Tuple[str, int]: ... +def utf_32_be_encode(__str: str, __errors: Optional[str] = ...) -> Tuple[bytes, int]: ... +def utf_32_decode(__data: bytes, __errors: Optional[str] = ..., __final: int = ...) -> Tuple[str, int]: ... +def utf_32_encode(__str: str, __errors: Optional[str] = ..., __byteorder: int = ...) -> Tuple[bytes, int]: ... def utf_32_ex_decode( - __data: _Decodable, __errors: _Errors = ..., __byteorder: int = ..., __final: int = ... -) -> Tuple[Text, int, int]: ... -def utf_32_le_decode(__data: _Decodable, __errors: _Errors = ..., __final: int = ...) -> Tuple[Text, int]: ... -def utf_32_le_encode(__str: _Encodable, __errors: _Errors = ...) -> Tuple[bytes, int]: ... -def utf_7_decode(__data: _Decodable, __errors: _Errors = ..., __final: int = ...) -> Tuple[Text, int]: ... -def utf_7_encode(__str: _Encodable, __errors: _Errors = ...) -> Tuple[bytes, int]: ... -def utf_8_decode(__data: _Decodable, __errors: _Errors = ..., __final: int = ...) -> Tuple[Text, int]: ... -def utf_8_encode(__str: _Encodable, __errors: _Errors = ...) -> Tuple[bytes, int]: ... + __data: bytes, __errors: Optional[str] = ..., __byteorder: int = ..., __final: int = ... +) -> Tuple[str, int, int]: ... +def utf_32_le_decode(__data: bytes, __errors: Optional[str] = ..., __final: int = ...) -> Tuple[str, int]: ... +def utf_32_le_encode(__str: str, __errors: Optional[str] = ...) -> Tuple[bytes, int]: ... +def utf_7_decode(__data: bytes, __errors: Optional[str] = ..., __final: int = ...) -> Tuple[str, int]: ... +def utf_7_encode(__str: str, __errors: Optional[str] = ...) -> Tuple[bytes, int]: ... +def utf_8_decode(__data: bytes, __errors: Optional[str] = ..., __final: int = ...) -> Tuple[str, int]: ... +def utf_8_encode(__str: str, __errors: Optional[str] = ...) -> Tuple[bytes, int]: ... if sys.platform == "win32": - def mbcs_decode(__data: _Decodable, __errors: _Errors = ..., __final: int = ...) -> Tuple[Text, int]: ... - def mbcs_encode(__str: _Encodable, __errors: _Errors = ...) -> Tuple[bytes, int]: ... - def code_page_decode(__codepage: int, __data: bytes, __errors: _Errors = ..., __final: int = ...) -> Tuple[Text, int]: ... - def code_page_encode(__code_page: int, __str: Text, __errors: _Errors = ...) -> Tuple[bytes, int]: ... - def oem_decode(__data: bytes, __errors: _Errors = ..., __final: int = ...) -> Tuple[Text, int]: ... - def oem_encode(__str: Text, __errors: _Errors = ...) -> Tuple[bytes, int]: ... + def mbcs_decode(__data: bytes, __errors: Optional[str] = ..., __final: int = ...) -> Tuple[str, int]: ... + def mbcs_encode(__str: str, __errors: Optional[str] = ...) -> Tuple[bytes, int]: ... + def code_page_decode( + __codepage: int, __data: bytes, __errors: Optional[str] = ..., __final: int = ... + ) -> Tuple[str, int]: ... + def code_page_encode(__code_page: int, __str: str, __errors: Optional[str] = ...) -> Tuple[bytes, int]: ... + def oem_decode(__data: bytes, __errors: Optional[str] = ..., __final: int = ...) -> Tuple[str, int]: ... + def oem_encode(__str: str, __errors: Optional[str] = ...) -> Tuple[bytes, int]: ... diff --git a/stdlib/argparse.pyi b/stdlib/argparse.pyi index 1a39e372f..2d5efdf4e 100644 --- a/stdlib/argparse.pyi +++ b/stdlib/argparse.pyi @@ -12,7 +12,6 @@ from typing import ( Pattern, Protocol, Sequence, - Text, Tuple, Type, TypeVar, @@ -24,8 +23,6 @@ _T = TypeVar("_T") _ActionT = TypeVar("_ActionT", bound=Action) _N = TypeVar("_N") -_Text = str - ONE_OR_MORE: str OPTIONAL: str PARSER: str @@ -46,40 +43,38 @@ class _AttributeHolder: # undocumented class _ActionsContainer: - description: Optional[_Text] - prefix_chars: _Text + description: Optional[str] + prefix_chars: str argument_default: Any - conflict_handler: _Text + conflict_handler: str - _registries: Dict[_Text, Dict[Any, Any]] + _registries: Dict[str, Dict[Any, Any]] _actions: List[Action] - _option_string_actions: Dict[_Text, Action] + _option_string_actions: Dict[str, 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] - def __init__( - self, description: Optional[Text], 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 __init__(self, description: Optional[str], prefix_chars: str, argument_default: Any, conflict_handler: str) -> None: ... + def register(self, registry_name: str, value: Any, object: Any) -> None: ... + def _registry_get(self, registry_name: str, value: Any, default: Any = ...) -> Any: ... def set_defaults(self, **kwargs: Any) -> None: ... - def get_default(self, dest: Text) -> Any: ... + def get_default(self, dest: str) -> Any: ... def add_argument( self, - *name_or_flags: Text, - action: Union[Text, Type[Action]] = ..., - nargs: Union[int, Text] = ..., + *name_or_flags: str, + action: Union[str, Type[Action]] = ..., + nargs: Union[int, str] = ..., const: Any = ..., default: Any = ..., - type: Union[Callable[[Text], _T], Callable[[str], _T], FileType] = ..., + type: Union[Callable[[str], _T], Callable[[str], _T], FileType] = ..., choices: Iterable[_T] = ..., required: bool = ..., - help: Optional[Text] = ..., - metavar: Optional[Union[Text, Tuple[Text, ...]]] = ..., - dest: Optional[Text] = ..., - version: Text = ..., + help: Optional[str] = ..., + metavar: Optional[Union[str, Tuple[str, ...]]] = ..., + dest: Optional[str] = ..., + version: str = ..., **kwargs: Any, ) -> Action: ... def add_argument_group(self, *args: Any, **kwargs: Any) -> _ArgumentGroup: ... @@ -87,23 +82,23 @@ 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_positional_kwargs(self, dest: str, **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 _get_handler(self) -> Callable[[Action, Iterable[Tuple[Text, Action]]], Any]: ... + def _get_handler(self) -> Callable[[Action, Iterable[Tuple[str, 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[str, Action]]) -> NoReturn: ... + def _handle_conflict_resolve(self, action: Action, conflicting_actions: Iterable[Tuple[str, Action]]) -> None: ... class _FormatterClass(Protocol): def __call__(self, prog: str) -> HelpFormatter: ... class ArgumentParser(_AttributeHolder, _ActionsContainer): - prog: _Text - usage: Optional[_Text] - epilog: Optional[_Text] + prog: str + usage: Optional[str] + epilog: Optional[str] formatter_class: _FormatterClass - fromfile_prefix_chars: Optional[_Text] + fromfile_prefix_chars: Optional[str] add_help: bool allow_abbrev: bool @@ -148,11 +143,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: Optional[Sequence[str]] = ...) -> Namespace: ... @overload - def parse_args(self, args: Optional[Sequence[Text]], namespace: None) -> Namespace: ... # type: ignore + def parse_args(self, args: Optional[Sequence[str]], namespace: None) -> Namespace: ... # type: ignore @overload - def parse_args(self, args: Optional[Sequence[Text]], namespace: _N) -> _N: ... + def parse_args(self, args: Optional[Sequence[str]], namespace: _N) -> _N: ... @overload def parse_args(self, *, namespace: None) -> Namespace: ... # type: ignore @overload @@ -176,26 +171,26 @@ class ArgumentParser(_AttributeHolder, _ActionsContainer): def add_subparsers( self, *, - title: Text = ..., - description: Optional[Text] = ..., - prog: Text = ..., + title: str = ..., + description: Optional[str] = ..., + prog: str = ..., parser_class: Type[ArgumentParser] = ..., action: Type[Action] = ..., - option_string: Text = ..., - dest: Optional[Text] = ..., - help: Optional[Text] = ..., - metavar: Optional[Text] = ..., + option_string: str = ..., + dest: Optional[str] = ..., + help: Optional[str] = ..., + metavar: Optional[str] = ..., ) -> _SubParsersAction: ... def print_usage(self, file: Optional[IO[str]] = ...) -> None: ... def print_help(self, file: Optional[IO[str]] = ...) -> 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: Optional[Sequence[str]] = ..., namespace: Optional[Namespace] = ... ) -> 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 error(self, message: Text) -> NoReturn: ... + def convert_arg_line_to_args(self, arg_line: str) -> List[str]: ... + def exit(self, status: int = ..., message: Optional[str] = ...) -> NoReturn: ... + def error(self, message: str) -> NoReturn: ... if sys.version_info >= (3, 7): def parse_intermixed_args( self, args: Optional[Sequence[str]] = ..., namespace: Optional[Namespace] = ... @@ -206,22 +201,22 @@ class ArgumentParser(_AttributeHolder, _ActionsContainer): # 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 _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 _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 _parse_known_args(self, arg_strings: List[str], namespace: Namespace) -> Tuple[Namespace, List[str]]: ... + def _read_args_from_files(self, arg_strings: List[str]) -> List[str]: ... + def _match_argument(self, action: Action, arg_strings_pattern: str) -> int: ... + def _match_arguments_partial(self, actions: Sequence[Action], arg_strings_pattern: str) -> List[int]: ... + def _parse_optional(self, arg_string: str) -> Optional[Tuple[Optional[Action], str, Optional[str]]]: ... + def _get_option_tuples(self, option_string: str) -> List[Tuple[Action, str, Optional[str]]]: ... + def _get_nargs_pattern(self, action: Action) -> str: ... + def _get_values(self, action: Action, arg_strings: List[str]) -> Any: ... + def _get_value(self, action: Action, arg_string: str) -> 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: ... class HelpFormatter: # undocumented - _prog: _Text + _prog: str _indent_increment: int _max_help_position: int _width: int @@ -234,37 +229,37 @@ 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: str, indent_increment: int = ..., max_help_position: int = ..., width: Optional[int] = ... ) -> 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 _add_item(self, func: Callable[..., str], args: Iterable[Any]) -> None: ... + def start_section(self, heading: Optional[str]) -> None: ... def end_section(self) -> None: ... - def add_text(self, text: Optional[Text]) -> None: ... + def add_text(self, text: Optional[str]) -> None: ... def add_usage( - self, usage: Optional[Text], actions: Iterable[Action], groups: Iterable[_ArgumentGroup], prefix: Optional[Text] = ... + self, usage: Optional[str], actions: Iterable[Action], groups: Iterable[_ArgumentGroup], prefix: Optional[str] = ... ) -> 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_help(self) -> str: ... + def _join_parts(self, part_strings: Iterable[str]) -> str: ... def _format_usage( - self, usage: Text, actions: Iterable[Action], groups: Iterable[_ArgumentGroup], prefix: Optional[Text] - ) -> _Text: ... - def _format_actions_usage(self, actions: Iterable[Action], groups: Iterable[_ArgumentGroup]) -> _Text: ... - 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 _format_args(self, action: Action, default_metavar: Text) -> _Text: ... - def _expand_help(self, action: Action) -> _Text: ... + self, usage: str, actions: Iterable[Action], groups: Iterable[_ArgumentGroup], prefix: Optional[str] + ) -> str: ... + def _format_actions_usage(self, actions: Iterable[Action], groups: Iterable[_ArgumentGroup]) -> str: ... + def _format_text(self, text: str) -> str: ... + def _format_action(self, action: Action) -> str: ... + def _format_action_invocation(self, action: Action) -> str: ... + def _metavar_formatter(self, action: Action, default_metavar: str) -> Callable[[int], Tuple[str, ...]]: ... + def _format_args(self, action: Action, default_metavar: str) -> str: ... + def _expand_help(self, action: Action) -> str: ... 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_default_metavar_for_optional(self, action: Action) -> _Text: ... - def _get_default_metavar_for_positional(self, action: Action) -> _Text: ... + def _split_lines(self, text: str, width: int) -> List[str]: ... + def _fill_text(self, text: str, width: int, indent: str) -> str: ... + def _get_help_string(self, action: Action) -> Optional[str]: ... + def _get_default_metavar_for_optional(self, action: Action) -> str: ... + def _get_default_metavar_for_positional(self, action: Action) -> str: ... class RawDescriptionHelpFormatter(HelpFormatter): ... class RawTextHelpFormatter(RawDescriptionHelpFormatter): ... @@ -272,35 +267,35 @@ class ArgumentDefaultsHelpFormatter(HelpFormatter): ... class MetavarTypeHelpFormatter(HelpFormatter): ... class Action(_AttributeHolder): - option_strings: Sequence[_Text] - dest: _Text - nargs: Optional[Union[int, _Text]] + option_strings: Sequence[str] + dest: str + nargs: Optional[Union[int, str]] const: Any default: Any type: Union[Callable[[str], Any], FileType, None] choices: Optional[Iterable[Any]] required: bool - help: Optional[_Text] - metavar: Optional[Union[_Text, Tuple[_Text, ...]]] + help: Optional[str] + metavar: Optional[Union[str, Tuple[str, ...]]] def __init__( self, - option_strings: Sequence[Text], - dest: Text, - nargs: Optional[Union[int, Text]] = ..., + option_strings: Sequence[str], + dest: str, + nargs: Optional[Union[int, str]] = ..., const: Optional[_T] = ..., default: Union[_T, str, None] = ..., - type: Optional[Union[Callable[[Text], _T], Callable[[str], _T], FileType]] = ..., + type: Optional[Union[Callable[[str], _T], Callable[[str], _T], FileType]] = ..., choices: Optional[Iterable[_T]] = ..., required: bool = ..., - help: Optional[Text] = ..., - metavar: Optional[Union[Text, Tuple[Text, ...]]] = ..., + help: Optional[str] = ..., + metavar: Optional[Union[str, Tuple[str, ...]]] = ..., ) -> None: ... def __call__( self, parser: ArgumentParser, namespace: Namespace, - values: Union[Text, Sequence[Any], None], - option_string: Optional[Text] = ..., + values: Union[str, Sequence[Any], None], + option_string: Optional[str] = ..., ) -> None: ... if sys.version_info >= (3, 9): def format_usage(self) -> str: ... @@ -312,36 +307,36 @@ if sys.version_info >= (3, 9): option_strings: Sequence[str], dest: str, default: Union[_T, str, None] = ..., - type: Optional[Union[Callable[[Text], _T], Callable[[str], _T], FileType]] = ..., + type: Optional[Union[Callable[[str], _T], Callable[[str], _T], FileType]] = ..., choices: Optional[Iterable[_T]] = ..., required: bool = ..., - help: Optional[Text] = ..., - metavar: Optional[Union[Text, Tuple[Text, ...]]] = ..., + help: Optional[str] = ..., + metavar: Optional[Union[str, Tuple[str, ...]]] = ..., ) -> None: ... class Namespace(_AttributeHolder): def __init__(self, **kwargs: Any) -> None: ... - def __getattr__(self, name: Text) -> Any: ... - def __setattr__(self, name: Text, value: Any) -> None: ... + def __getattr__(self, name: str) -> Any: ... + def __setattr__(self, name: str, value: Any) -> None: ... def __contains__(self, key: str) -> bool: ... class FileType: # undocumented - _mode: _Text + _mode: str _bufsize: int _encoding: Optional[str] _errors: Optional[str] def __init__( self, mode: str = ..., bufsize: int = ..., encoding: Optional[str] = ..., errors: Optional[str] = ... ) -> None: ... - def __call__(self, string: Text) -> IO[Any]: ... + def __call__(self, string: str) -> IO[Any]: ... # undocumented class _ArgumentGroup(_ActionsContainer): - title: Optional[_Text] + title: Optional[str] _group_actions: List[Action] def __init__( - self, container: _ActionsContainer, title: Optional[Text] = ..., description: Optional[Text] = ..., **kwargs: Any + self, container: _ActionsContainer, title: Optional[str] = ..., description: Optional[str] = ..., **kwargs: Any ) -> None: ... # undocumented @@ -357,25 +352,25 @@ class _StoreAction(Action): ... class _StoreConstAction(Action): def __init__( self, - option_strings: Sequence[Text], - dest: Text, + option_strings: Sequence[str], + dest: str, const: Any, default: Any = ..., required: bool = ..., - help: Optional[Text] = ..., - metavar: Optional[Union[Text, Tuple[Text, ...]]] = ..., + help: Optional[str] = ..., + metavar: Optional[Union[str, Tuple[str, ...]]] = ..., ) -> 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[str], dest: str, default: bool = ..., required: bool = ..., help: Optional[str] = ... ) -> 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[str], dest: str, default: bool = ..., required: bool = ..., help: Optional[str] = ... ) -> None: ... # undocumented @@ -385,70 +380,63 @@ class _AppendAction(Action): ... class _AppendConstAction(Action): def __init__( self, - option_strings: Sequence[Text], - dest: Text, + option_strings: Sequence[str], + dest: str, const: Any, default: Any = ..., required: bool = ..., - help: Optional[Text] = ..., - metavar: Optional[Union[Text, Tuple[Text, ...]]] = ..., + help: Optional[str] = ..., + metavar: Optional[Union[str, Tuple[str, ...]]] = ..., ) -> 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[str], dest: str, default: Any = ..., required: bool = ..., help: Optional[str] = ... ) -> None: ... # undocumented class _HelpAction(Action): - def __init__( - self, option_strings: Sequence[Text], dest: Text = ..., default: Text = ..., help: Optional[Text] = ... - ) -> None: ... + def __init__(self, option_strings: Sequence[str], dest: str = ..., default: str = ..., help: Optional[str] = ...) -> None: ... # undocumented class _VersionAction(Action): - version: Optional[_Text] + version: Optional[str] def __init__( - self, - option_strings: Sequence[Text], - version: Optional[Text] = ..., - dest: Text = ..., - default: Text = ..., - help: Text = ..., + self, option_strings: Sequence[str], version: Optional[str] = ..., dest: str = ..., default: str = ..., help: str = ... ) -> None: ... # undocumented class _SubParsersAction(Action): _ChoicesPseudoAction: Type[Any] # nested class - _prog_prefix: _Text + _prog_prefix: str _parser_class: Type[ArgumentParser] - _name_parser_map: Dict[_Text, ArgumentParser] - choices: Dict[_Text, ArgumentParser] + _name_parser_map: Dict[str, ArgumentParser] + choices: Dict[str, ArgumentParser] _choices_actions: List[Action] if sys.version_info >= (3, 7): def __init__( self, - option_strings: Sequence[Text], - prog: Text, + option_strings: Sequence[str], + prog: str, parser_class: Type[ArgumentParser], - dest: Text = ..., + dest: str = ..., required: bool = ..., - help: Optional[Text] = ..., - metavar: Optional[Union[Text, Tuple[Text, ...]]] = ..., + help: Optional[str] = ..., + metavar: Optional[Union[str, Tuple[str, ...]]] = ..., ) -> None: ... else: def __init__( self, - option_strings: Sequence[Text], - prog: Text, + option_strings: Sequence[str], + prog: str, parser_class: Type[ArgumentParser], - dest: Text = ..., - help: Optional[Text] = ..., - metavar: Optional[Union[Text, Tuple[Text, ...]]] = ..., + dest: str = ..., + help: Optional[str] = ..., + metavar: Optional[Union[str, Tuple[str, ...]]] = ..., ) -> None: ... # TODO: Type keyword args properly. - def add_parser(self, name: Text, **kwargs: Any) -> ArgumentParser: ... + def add_parser(self, name: str, **kwargs: Any) -> ArgumentParser: ... def _get_subactions(self) -> List[Action]: ... # undocumented @@ -456,7 +444,7 @@ class ArgumentTypeError(Exception): ... if sys.version_info < (3, 7): # undocumented - def _ensure_value(namespace: Namespace, name: Text, value: Any) -> Any: ... + def _ensure_value(namespace: Namespace, name: str, value: Any) -> Any: ... # undocumented def _get_action_name(argument: Optional[Action]) -> Optional[str]: ... diff --git a/stdlib/asyncio/streams.pyi b/stdlib/asyncio/streams.pyi index a63672010..f0879b8da 100644 --- a/stdlib/asyncio/streams.pyi +++ b/stdlib/asyncio/streams.pyi @@ -1,4 +1,5 @@ import sys +from _typeshed import StrPath from typing import Any, AsyncIterator, Awaitable, Callable, Iterable, Optional, Tuple, Union from . import events, protocols, transports @@ -36,9 +37,7 @@ async def start_server( if sys.platform != "win32": if sys.version_info >= (3, 7): - from os import PathLike - - _PathType = Union[str, PathLike[str]] + _PathType = StrPath else: _PathType = str async def open_unix_connection( diff --git a/stdlib/base64.pyi b/stdlib/base64.pyi index 23ea4b358..47118516c 100644 --- a/stdlib/base64.pyi +++ b/stdlib/base64.pyi @@ -1,28 +1,27 @@ import sys from typing import IO, Optional, Union -_encodable = bytes -_decodable = Union[bytes, str] - -def b64encode(s: _encodable, altchars: Optional[bytes] = ...) -> bytes: ... -def b64decode(s: _decodable, altchars: Optional[bytes] = ..., validate: bool = ...) -> bytes: ... -def standard_b64encode(s: _encodable) -> bytes: ... -def standard_b64decode(s: _decodable) -> bytes: ... -def urlsafe_b64encode(s: _encodable) -> bytes: ... -def urlsafe_b64decode(s: _decodable) -> bytes: ... -def b32encode(s: _encodable) -> bytes: ... -def b32decode(s: _decodable, casefold: bool = ..., map01: Optional[bytes] = ...) -> bytes: ... -def b16encode(s: _encodable) -> bytes: ... -def b16decode(s: _decodable, casefold: bool = ...) -> bytes: ... +def b64encode(s: bytes, altchars: Optional[bytes] = ...) -> bytes: ... +def b64decode(s: Union[str, bytes], altchars: Optional[bytes] = ..., validate: bool = ...) -> bytes: ... +def standard_b64encode(s: bytes) -> bytes: ... +def standard_b64decode(s: Union[str, bytes]) -> bytes: ... +def urlsafe_b64encode(s: bytes) -> bytes: ... +def urlsafe_b64decode(s: Union[str, bytes]) -> bytes: ... +def b32encode(s: bytes) -> bytes: ... +def b32decode(s: Union[str, bytes], casefold: bool = ..., map01: Optional[bytes] = ...) -> bytes: ... +def b16encode(s: bytes) -> bytes: ... +def b16decode(s: Union[str, bytes], casefold: bool = ...) -> bytes: ... if sys.version_info >= (3, 10): - def b32hexencode(s: _encodable) -> bytes: ... - def b32hexdecode(s: _decodable, casefold: bool = ...) -> bytes: ... + def b32hexencode(s: bytes) -> bytes: ... + def b32hexdecode(s: Union[str, bytes], casefold: bool = ...) -> bytes: ... -def a85encode(b: _encodable, *, foldspaces: bool = ..., wrapcol: int = ..., pad: bool = ..., adobe: bool = ...) -> bytes: ... -def a85decode(b: _decodable, *, foldspaces: bool = ..., adobe: bool = ..., ignorechars: Union[str, bytes] = ...) -> bytes: ... -def b85encode(b: _encodable, pad: bool = ...) -> bytes: ... -def b85decode(b: _decodable) -> bytes: ... +def a85encode(b: bytes, *, foldspaces: bool = ..., wrapcol: int = ..., pad: bool = ..., adobe: bool = ...) -> bytes: ... +def a85decode( + b: Union[str, bytes], *, foldspaces: bool = ..., adobe: bool = ..., ignorechars: Union[str, bytes] = ... +) -> bytes: ... +def b85encode(b: bytes, pad: bool = ...) -> bytes: ... +def b85decode(b: Union[str, bytes]) -> bytes: ... def decode(input: IO[bytes], output: IO[bytes]) -> None: ... def encode(input: IO[bytes], output: IO[bytes]) -> None: ... def encodebytes(s: bytes) -> bytes: ... diff --git a/stdlib/binascii.pyi b/stdlib/binascii.pyi index 70b330ad9..b74df13c3 100644 --- a/stdlib/binascii.pyi +++ b/stdlib/binascii.pyi @@ -1,39 +1,34 @@ import sys from typing import Union -# Since Python 3.3 ASCII-only unicode strings are accepted by the -# a2b_* functions. -_Bytes = bytes -_Ascii = Union[bytes, str] - -def a2b_uu(__data: _Ascii) -> bytes: ... +def a2b_uu(__data: Union[str, bytes]) -> bytes: ... if sys.version_info >= (3, 7): - def b2a_uu(__data: _Bytes, *, backtick: bool = ...) -> bytes: ... + def b2a_uu(__data: bytes, *, backtick: bool = ...) -> bytes: ... else: - def b2a_uu(__data: _Bytes) -> bytes: ... + def b2a_uu(__data: bytes) -> bytes: ... -def a2b_base64(__data: _Ascii) -> bytes: ... -def b2a_base64(__data: _Bytes, *, newline: bool = ...) -> bytes: ... -def a2b_qp(data: _Ascii, header: bool = ...) -> bytes: ... -def b2a_qp(data: _Bytes, quotetabs: bool = ..., istext: bool = ..., header: bool = ...) -> bytes: ... -def a2b_hqx(__data: _Ascii) -> bytes: ... -def rledecode_hqx(__data: _Bytes) -> bytes: ... -def rlecode_hqx(__data: _Bytes) -> bytes: ... -def b2a_hqx(__data: _Bytes) -> bytes: ... -def crc_hqx(__data: _Bytes, __crc: int) -> int: ... -def crc32(__data: _Bytes, __crc: int = ...) -> int: ... -def b2a_hex(__data: _Bytes) -> bytes: ... +def a2b_base64(__data: Union[str, bytes]) -> bytes: ... +def b2a_base64(__data: bytes, *, newline: bool = ...) -> bytes: ... +def a2b_qp(data: Union[str, bytes], header: bool = ...) -> bytes: ... +def b2a_qp(data: bytes, quotetabs: bool = ..., istext: bool = ..., header: bool = ...) -> bytes: ... +def a2b_hqx(__data: Union[str, bytes]) -> bytes: ... +def rledecode_hqx(__data: bytes) -> bytes: ... +def rlecode_hqx(__data: bytes) -> bytes: ... +def b2a_hqx(__data: bytes) -> bytes: ... +def crc_hqx(__data: bytes, __crc: int) -> int: ... +def crc32(__data: bytes, __crc: int = ...) -> int: ... +def b2a_hex(__data: bytes) -> bytes: ... if sys.version_info >= (3, 8): def hexlify(data: bytes, sep: Union[str, bytes] = ..., bytes_per_sep: int = ...) -> bytes: ... else: - def hexlify(__data: _Bytes) -> bytes: ... + def hexlify(__data: bytes) -> bytes: ... -def a2b_hex(__hexstr: _Ascii) -> bytes: ... -def unhexlify(__hexstr: _Ascii) -> bytes: ... +def a2b_hex(__hexstr: Union[str, bytes]) -> bytes: ... +def unhexlify(__hexstr: Union[str, bytes]) -> bytes: ... class Error(ValueError): ... class Incomplete(Exception): ... diff --git a/stdlib/datetime.pyi b/stdlib/datetime.pyi index 1ba62e144..c46d01265 100644 --- a/stdlib/datetime.pyi +++ b/stdlib/datetime.pyi @@ -4,7 +4,6 @@ from typing import ClassVar, NamedTuple, Optional, SupportsAbs, Tuple, Type, Typ _S = TypeVar("_S") -_Text = str MINYEAR: int MAXYEAR: int @@ -14,6 +13,9 @@ class tzinfo: def dst(self, dt: Optional[datetime]) -> Optional[timedelta]: ... def fromutc(self, dt: datetime) -> datetime: ... +# Alias required to avoid name conflicts with date(time).tzinfo. +_tzinfo = tzinfo + class timezone(tzinfo): utc: ClassVar[timezone] min: ClassVar[timezone] @@ -27,8 +29,6 @@ if sys.version_info >= (3, 9): week: int weekday: int -_tzinfo = tzinfo - class date: min: ClassVar[date] max: ClassVar[date] @@ -53,7 +53,7 @@ class date: @property def day(self) -> int: ... def ctime(self) -> str: ... - def strftime(self, fmt: _Text) -> str: ... + def strftime(self, fmt: str) -> str: ... def __format__(self, fmt: str) -> str: ... def isoformat(self) -> str: ... def timetuple(self) -> struct_time: ... @@ -116,7 +116,7 @@ class time: if sys.version_info >= (3, 7): @classmethod def fromisoformat(cls: Type[_S], time_string: str) -> _S: ... - def strftime(self, fmt: _Text) -> str: ... + def strftime(self, fmt: str) -> str: ... def __format__(self, fmt: str) -> str: ... def utcoffset(self) -> Optional[timedelta]: ... def tzname(self) -> Optional[str]: ... @@ -243,7 +243,7 @@ class datetime(date): if sys.version_info >= (3, 7): @classmethod def fromisoformat(cls: Type[_S], date_string: str) -> _S: ... - def strftime(self, fmt: _Text) -> str: ... + def strftime(self, fmt: str) -> str: ... def __format__(self, fmt: str) -> str: ... def toordinal(self) -> int: ... def timetuple(self) -> struct_time: ... @@ -272,7 +272,7 @@ class datetime(date): def ctime(self) -> str: ... def isoformat(self, sep: str = ..., timespec: str = ...) -> str: ... @classmethod - def strptime(cls, date_string: _Text, format: _Text) -> datetime: ... + def strptime(cls, date_string: str, format: str) -> datetime: ... def utcoffset(self) -> Optional[timedelta]: ... def tzname(self) -> Optional[str]: ... def dst(self) -> Optional[timedelta]: ... diff --git a/stdlib/difflib.pyi b/stdlib/difflib.pyi index c940b3a5a..9dd98d331 100644 --- a/stdlib/difflib.pyi +++ b/stdlib/difflib.pyi @@ -10,7 +10,6 @@ from typing import ( NamedTuple, Optional, Sequence, - Text, Tuple, TypeVar, Union, @@ -21,8 +20,7 @@ if sys.version_info >= (3, 9): from types import GenericAlias _T = TypeVar("_T") -_StrType = Text -_JunkCallback = Union[Callable[[Text], bool], Callable[[str], bool]] +_JunkCallback = Union[Callable[[str], bool], Callable[[str], bool]] class Match(NamedTuple): a: int @@ -63,33 +61,33 @@ def get_close_matches( class Differ: def __init__(self, linejunk: Optional[_JunkCallback] = ..., charjunk: Optional[_JunkCallback] = ...) -> None: ... - def compare(self, a: Sequence[_StrType], b: Sequence[_StrType]) -> Iterator[_StrType]: ... + def compare(self, a: Sequence[str], b: Sequence[str]) -> Iterator[str]: ... -def IS_LINE_JUNK(line: _StrType, pat: Any = ...) -> bool: ... # pat is undocumented -def IS_CHARACTER_JUNK(ch: _StrType, ws: _StrType = ...) -> bool: ... # ws is undocumented +def IS_LINE_JUNK(line: str, pat: Any = ...) -> bool: ... # pat is undocumented +def IS_CHARACTER_JUNK(ch: str, ws: str = ...) -> bool: ... # ws is undocumented def unified_diff( - a: Sequence[_StrType], - b: Sequence[_StrType], - fromfile: _StrType = ..., - tofile: _StrType = ..., - fromfiledate: _StrType = ..., - tofiledate: _StrType = ..., + a: Sequence[str], + b: Sequence[str], + fromfile: str = ..., + tofile: str = ..., + fromfiledate: str = ..., + tofiledate: str = ..., n: int = ..., - lineterm: _StrType = ..., -) -> Iterator[_StrType]: ... + lineterm: str = ..., +) -> Iterator[str]: ... def context_diff( - a: Sequence[_StrType], - b: Sequence[_StrType], - fromfile: _StrType = ..., - tofile: _StrType = ..., - fromfiledate: _StrType = ..., - tofiledate: _StrType = ..., + a: Sequence[str], + b: Sequence[str], + fromfile: str = ..., + tofile: str = ..., + fromfiledate: str = ..., + tofiledate: str = ..., n: int = ..., - lineterm: _StrType = ..., -) -> Iterator[_StrType]: ... + lineterm: str = ..., +) -> Iterator[str]: ... def ndiff( - a: Sequence[_StrType], b: Sequence[_StrType], linejunk: Optional[_JunkCallback] = ..., charjunk: Optional[_JunkCallback] = ... -) -> Iterator[_StrType]: ... + a: Sequence[str], b: Sequence[str], linejunk: Optional[_JunkCallback] = ..., charjunk: Optional[_JunkCallback] = ... +) -> Iterator[str]: ... class HtmlDiff(object): def __init__( @@ -101,26 +99,26 @@ class HtmlDiff(object): ) -> None: ... def make_file( self, - fromlines: Sequence[_StrType], - tolines: Sequence[_StrType], - fromdesc: _StrType = ..., - todesc: _StrType = ..., + fromlines: Sequence[str], + tolines: Sequence[str], + fromdesc: str = ..., + todesc: str = ..., context: bool = ..., numlines: int = ..., *, charset: str = ..., - ) -> _StrType: ... + ) -> str: ... def make_table( self, - fromlines: Sequence[_StrType], - tolines: Sequence[_StrType], - fromdesc: _StrType = ..., - todesc: _StrType = ..., + fromlines: Sequence[str], + tolines: Sequence[str], + fromdesc: str = ..., + todesc: str = ..., context: bool = ..., numlines: int = ..., - ) -> _StrType: ... + ) -> str: ... -def restore(delta: Iterable[_StrType], which: int) -> Iterator[_StrType]: ... +def restore(delta: Iterable[str], which: int) -> Iterator[str]: ... def diff_bytes( dfunc: Callable[[Sequence[str], Sequence[str], str, str, str, str, int, str], Iterator[str]], a: Sequence[bytes], diff --git a/stdlib/filecmp.pyi b/stdlib/filecmp.pyi index c397ff20b..4dd763e82 100644 --- a/stdlib/filecmp.pyi +++ b/stdlib/filecmp.pyi @@ -1,15 +1,14 @@ import sys +from _typeshed import AnyPath from os import PathLike -from typing import Any, AnyStr, Callable, Dict, Generic, Iterable, List, Optional, Sequence, Text, Tuple, Union +from typing import Any, AnyStr, Callable, Dict, Generic, Iterable, List, Optional, Sequence, Tuple, Union if sys.version_info >= (3, 9): from types import GenericAlias DEFAULT_IGNORES: List[str] -def cmp( - f1: Union[bytes, Text, PathLike[AnyStr]], f2: Union[bytes, Text, PathLike[AnyStr]], shallow: Union[int, bool] = ... -) -> bool: ... +def cmp(f1: AnyPath, f2: AnyPath, shallow: Union[int, bool] = ...) -> bool: ... def cmpfiles( a: Union[AnyStr, PathLike[AnyStr]], b: Union[AnyStr, PathLike[AnyStr]], diff --git a/stdlib/http/cookiejar.pyi b/stdlib/http/cookiejar.pyi index 9398bae00..094cebe49 100644 --- a/stdlib/http/cookiejar.pyi +++ b/stdlib/http/cookiejar.pyi @@ -1,6 +1,6 @@ import sys +from _typeshed import StrPath from http.client import HTTPResponse -from os import PathLike from typing import Dict, Iterable, Iterator, Optional, Sequence, Tuple, TypeVar, Union, overload from urllib.request import Request @@ -26,7 +26,7 @@ class FileCookieJar(CookieJar): delayload: bool if sys.version_info >= (3, 8): def __init__( - self, filename: Optional[Union[str, PathLike[str]]] = ..., delayload: bool = ..., policy: Optional[CookiePolicy] = ... + self, filename: Optional[StrPath] = ..., delayload: bool = ..., policy: Optional[CookiePolicy] = ... ) -> None: ... else: def __init__( diff --git a/stdlib/http/server.pyi b/stdlib/http/server.pyi index f9a13d013..5d06bd5c7 100644 --- a/stdlib/http/server.pyi +++ b/stdlib/http/server.pyi @@ -1,7 +1,7 @@ import email.message import socketserver import sys -from os import PathLike +from _typeshed import StrPath from typing import Any, ClassVar, Dict, List, Mapping, Optional, Sequence, Tuple, Union class HTTPServer(socketserver.TCPServer): @@ -57,7 +57,7 @@ class SimpleHTTPRequestHandler(BaseHTTPRequestHandler): request: bytes, client_address: Tuple[str, int], server: socketserver.BaseServer, - directory: Optional[Union[str, PathLike[str]]] = ..., + directory: Optional[StrPath] = ..., ) -> None: ... else: def __init__(self, request: bytes, client_address: Tuple[str, int], server: socketserver.BaseServer) -> None: ... diff --git a/stdlib/imghdr.pyi b/stdlib/imghdr.pyi index 0604c52ce..2b28b718a 100644 --- a/stdlib/imghdr.pyi +++ b/stdlib/imghdr.pyi @@ -1,15 +1,13 @@ -import os -from typing import Any, BinaryIO, Callable, List, Optional, Protocol, Text, Union, overload +from _typeshed import StrPath +from typing import Any, BinaryIO, Callable, List, Optional, Protocol, Union, overload class _ReadableBinary(Protocol): def tell(self) -> int: ... def read(self, size: int) -> bytes: ... def seek(self, offset: int) -> Any: ... -_File = Union[Text, os.PathLike[Text], _ReadableBinary] - @overload -def what(file: _File, h: None = ...) -> Optional[str]: ... +def what(file: Union[StrPath, _ReadableBinary], h: None = ...) -> Optional[str]: ... @overload def what(file: Any, h: bytes) -> Optional[str]: ... diff --git a/stdlib/locale.pyi b/stdlib/locale.pyi index 22bee4019..5d1dd3fea 100644 --- a/stdlib/locale.pyi +++ b/stdlib/locale.pyi @@ -1,6 +1,4 @@ import sys - -# workaround for mypy#2010 from builtins import str as _str from decimal import Decimal from typing import Any, Callable, Dict, Iterable, List, Mapping, Optional, Sequence, Tuple, Union diff --git a/stdlib/optparse.pyi b/stdlib/optparse.pyi index 71b1fc2f6..ff8ce8ea9 100644 --- a/stdlib/optparse.pyi +++ b/stdlib/optparse.pyi @@ -1,124 +1,123 @@ from typing import IO, Any, AnyStr, Callable, Dict, Iterable, List, Mapping, Optional, Sequence, Tuple, Type, overload -_Text = str -NO_DEFAULT: Tuple[_Text, ...] -SUPPRESS_HELP: _Text -SUPPRESS_USAGE: _Text +NO_DEFAULT: Tuple[str, ...] +SUPPRESS_HELP: str +SUPPRESS_USAGE: str -def check_builtin(option: Option, opt: Any, value: _Text) -> Any: ... -def check_choice(option: Option, opt: Any, value: _Text) -> Any: ... +def check_builtin(option: Option, opt: Any, value: str) -> Any: ... +def check_choice(option: Option, opt: Any, value: str) -> Any: ... class OptParseError(Exception): - msg: _Text - def __init__(self, msg: _Text) -> None: ... + msg: str + def __init__(self, msg: str) -> None: ... class BadOptionError(OptParseError): - opt_str: _Text - def __init__(self, opt_str: _Text) -> None: ... + opt_str: str + def __init__(self, opt_str: str) -> None: ... class AmbiguousOptionError(BadOptionError): - possibilities: Iterable[_Text] - def __init__(self, opt_str: _Text, possibilities: Sequence[_Text]) -> None: ... + possibilities: Iterable[str] + def __init__(self, opt_str: str, possibilities: Sequence[str]) -> None: ... class OptionError(OptParseError): - msg: _Text - option_id: _Text - def __init__(self, msg: _Text, option: Option) -> None: ... + msg: str + option_id: str + def __init__(self, msg: str, option: Option) -> None: ... class OptionConflictError(OptionError): ... class OptionValueError(OptParseError): ... class HelpFormatter: - NO_DEFAULT_VALUE: _Text - _long_opt_fmt: _Text - _short_opt_fmt: _Text + NO_DEFAULT_VALUE: str + _long_opt_fmt: str + _short_opt_fmt: str current_indent: int - default_tag: _Text + default_tag: str help_position: Any help_width: Any indent_increment: int level: int max_help_position: int - option_strings: Dict[Option, _Text] + option_strings: Dict[Option, str] parser: OptionParser short_first: Any width: int def __init__(self, indent_increment: int, max_help_position: int, width: Optional[int], short_first: int) -> None: ... def dedent(self) -> None: ... - def expand_default(self, option: Option) -> _Text: ... - def format_description(self, description: _Text) -> _Text: ... - def format_epilog(self, epilog: _Text) -> _Text: ... - def format_heading(self, heading: Any) -> _Text: ... - def format_option(self, option: Option) -> _Text: ... - def format_option_strings(self, option: Option) -> _Text: ... - def format_usage(self, usage: Any) -> _Text: ... + def expand_default(self, option: Option) -> str: ... + def format_description(self, description: str) -> str: ... + def format_epilog(self, epilog: str) -> str: ... + def format_heading(self, heading: Any) -> str: ... + def format_option(self, option: Option) -> str: ... + def format_option_strings(self, option: Option) -> str: ... + def format_usage(self, usage: Any) -> str: ... def indent(self) -> None: ... - def set_long_opt_delimiter(self, delim: _Text) -> None: ... + def set_long_opt_delimiter(self, delim: str) -> None: ... def set_parser(self, parser: OptionParser) -> None: ... - def set_short_opt_delimiter(self, delim: _Text) -> None: ... + def set_short_opt_delimiter(self, delim: str) -> None: ... def store_option_strings(self, parser: OptionParser) -> None: ... class IndentedHelpFormatter(HelpFormatter): def __init__( self, indent_increment: int = ..., max_help_position: int = ..., width: Optional[int] = ..., short_first: int = ... ) -> None: ... - def format_heading(self, heading: _Text) -> _Text: ... - def format_usage(self, usage: _Text) -> _Text: ... + def format_heading(self, heading: str) -> str: ... + def format_usage(self, usage: str) -> str: ... class TitledHelpFormatter(HelpFormatter): def __init__( self, indent_increment: int = ..., max_help_position: int = ..., width: Optional[int] = ..., short_first: int = ... ) -> None: ... - def format_heading(self, heading: _Text) -> _Text: ... - def format_usage(self, usage: _Text) -> _Text: ... + def format_heading(self, heading: str) -> str: ... + def format_usage(self, usage: str) -> str: ... class Option: - ACTIONS: Tuple[_Text, ...] - ALWAYS_TYPED_ACTIONS: Tuple[_Text, ...] - ATTRS: List[_Text] + ACTIONS: Tuple[str, ...] + ALWAYS_TYPED_ACTIONS: Tuple[str, ...] + ATTRS: List[str] CHECK_METHODS: Optional[List[Callable[..., Any]]] - CONST_ACTIONS: Tuple[_Text, ...] - STORE_ACTIONS: Tuple[_Text, ...] - TYPED_ACTIONS: Tuple[_Text, ...] - TYPES: Tuple[_Text, ...] - TYPE_CHECKER: Dict[_Text, Callable[..., Any]] - _long_opts: List[_Text] - _short_opts: List[_Text] - action: _Text - dest: Optional[_Text] + CONST_ACTIONS: Tuple[str, ...] + STORE_ACTIONS: Tuple[str, ...] + TYPED_ACTIONS: Tuple[str, ...] + TYPES: Tuple[str, ...] + TYPE_CHECKER: Dict[str, Callable[..., Any]] + _long_opts: List[str] + _short_opts: List[str] + action: str + dest: Optional[str] default: Any nargs: int type: Any callback: Optional[Callable[..., Any]] callback_args: Optional[Tuple[Any, ...]] - callback_kwargs: Optional[Dict[_Text, Any]] - help: Optional[_Text] - metavar: Optional[_Text] - def __init__(self, *opts: Optional[_Text], **attrs: Any) -> None: ... + callback_kwargs: Optional[Dict[str, Any]] + help: Optional[str] + metavar: Optional[str] + def __init__(self, *opts: Optional[str], **attrs: Any) -> None: ... def _check_action(self) -> None: ... def _check_callback(self) -> None: ... def _check_choice(self) -> None: ... def _check_const(self) -> None: ... def _check_dest(self) -> None: ... def _check_nargs(self) -> None: ... - def _check_opt_strings(self, opts: Iterable[Optional[_Text]]) -> List[_Text]: ... + def _check_opt_strings(self, opts: Iterable[Optional[str]]) -> List[str]: ... def _check_type(self) -> None: ... - def _set_attrs(self, attrs: Dict[_Text, Any]) -> None: ... - def _set_opt_strings(self, opts: Iterable[_Text]) -> None: ... - def check_value(self, opt: _Text, value: Any) -> Any: ... - def convert_value(self, opt: _Text, value: Any) -> Any: ... - def get_opt_string(self) -> _Text: ... + def _set_attrs(self, attrs: Dict[str, Any]) -> None: ... + def _set_opt_strings(self, opts: Iterable[str]) -> None: ... + def check_value(self, opt: str, value: Any) -> Any: ... + def convert_value(self, opt: str, value: Any) -> Any: ... + def get_opt_string(self) -> str: ... def process(self, opt: Any, value: Any, values: Any, parser: OptionParser) -> int: ... - def take_action(self, action: _Text, dest: _Text, opt: Any, value: Any, values: Any, parser: OptionParser) -> int: ... + def take_action(self, action: str, dest: str, opt: Any, value: Any, values: Any, parser: OptionParser) -> int: ... def takes_value(self) -> bool: ... make_option = Option class OptionContainer: - _long_opt: Dict[_Text, Option] - _short_opt: Dict[_Text, Option] - conflict_handler: _Text - defaults: Dict[_Text, Any] + _long_opt: Dict[str, Option] + _short_opt: Dict[str, Option] + conflict_handler: str + defaults: Dict[str, Any] description: Any option_class: Type[Option] def __init__(self, option_class: Type[Option], conflict_handler: Any, description: Any) -> None: ... @@ -128,64 +127,64 @@ class OptionContainer: @overload def add_option(self, opt: Option) -> Option: ... @overload - def add_option(self, *args: Optional[_Text], **kwargs: Any) -> Any: ... + def add_option(self, *args: Optional[str], **kwargs: Any) -> Any: ... def add_options(self, option_list: Iterable[Option]) -> None: ... def destroy(self) -> None: ... def format_description(self, formatter: Optional[HelpFormatter]) -> Any: ... - def format_help(self, formatter: Optional[HelpFormatter]) -> _Text: ... - def format_option_help(self, formatter: Optional[HelpFormatter]) -> _Text: ... + def format_help(self, formatter: Optional[HelpFormatter]) -> str: ... + def format_option_help(self, formatter: Optional[HelpFormatter]) -> str: ... def get_description(self) -> Any: ... - def get_option(self, opt_str: _Text) -> Optional[Option]: ... - def has_option(self, opt_str: _Text) -> bool: ... - def remove_option(self, opt_str: _Text) -> None: ... + def get_option(self, opt_str: str) -> Optional[Option]: ... + def has_option(self, opt_str: str) -> bool: ... + def remove_option(self, opt_str: str) -> None: ... def set_conflict_handler(self, handler: Any) -> None: ... def set_description(self, description: Any) -> None: ... class OptionGroup(OptionContainer): option_list: List[Option] parser: OptionParser - title: _Text - def __init__(self, parser: OptionParser, title: _Text, description: Optional[_Text] = ...) -> None: ... + title: str + def __init__(self, parser: OptionParser, title: str, description: Optional[str] = ...) -> None: ... def _create_option_list(self) -> None: ... - def set_title(self, title: _Text) -> None: ... + def set_title(self, title: str) -> None: ... class Values: def __init__(self, defaults: Optional[Mapping[str, Any]] = ...) -> None: ... - def _update(self, dict: Mapping[_Text, Any], mode: Any) -> None: ... - def _update_careful(self, dict: Mapping[_Text, Any]) -> None: ... - def _update_loose(self, dict: Mapping[_Text, Any]) -> None: ... - def ensure_value(self, attr: _Text, value: Any) -> Any: ... - def read_file(self, filename: _Text, mode: _Text = ...) -> None: ... - def read_module(self, modname: _Text, mode: _Text = ...) -> None: ... + def _update(self, dict: Mapping[str, Any], mode: Any) -> None: ... + def _update_careful(self, dict: Mapping[str, Any]) -> None: ... + def _update_loose(self, dict: Mapping[str, Any]) -> None: ... + def ensure_value(self, attr: str, value: Any) -> Any: ... + def read_file(self, filename: str, mode: str = ...) -> None: ... + def read_module(self, modname: str, mode: str = ...) -> None: ... def __getattr__(self, name: str) -> Any: ... def __setattr__(self, name: str, value: Any) -> None: ... class OptionParser(OptionContainer): allow_interspersed_args: bool - epilog: Optional[_Text] + epilog: Optional[str] formatter: HelpFormatter - largs: Optional[List[_Text]] + largs: Optional[List[str]] option_groups: List[OptionGroup] option_list: List[Option] process_default_values: Any - prog: Optional[_Text] + prog: Optional[str] rargs: Optional[List[Any]] standard_option_list: List[Option] - usage: Optional[_Text] + usage: Optional[str] values: Optional[Values] - version: _Text + version: str def __init__( self, - usage: Optional[_Text] = ..., + usage: Optional[str] = ..., option_list: Optional[Iterable[Option]] = ..., option_class: Type[Option] = ..., - version: Optional[_Text] = ..., - conflict_handler: _Text = ..., - description: Optional[_Text] = ..., + version: Optional[str] = ..., + conflict_handler: str = ..., + description: Optional[str] = ..., formatter: Optional[HelpFormatter] = ..., add_help_option: bool = ..., - prog: Optional[_Text] = ..., - epilog: Optional[_Text] = ..., + prog: Optional[str] = ..., + epilog: Optional[str] = ..., ) -> None: ... def _add_help_option(self) -> None: ... def _add_version_option(self) -> None: ... @@ -193,7 +192,7 @@ class OptionParser(OptionContainer): def _get_all_options(self) -> List[Option]: ... def _get_args(self, args: Iterable[Any]) -> List[Any]: ... def _init_parsing_state(self) -> None: ... - def _match_long_opt(self, opt: _Text) -> _Text: ... + def _match_long_opt(self, opt: str) -> str: ... def _populate_option_list(self, option_list: Iterable[Option], add_help: bool = ...) -> None: ... def _process_args(self, largs: List[Any], rargs: List[Any], values: Values) -> None: ... def _process_long_opt(self, rargs: List[Any], values: Any) -> None: ... @@ -202,20 +201,20 @@ class OptionParser(OptionContainer): def add_option_group(self, __opt_group: OptionGroup) -> OptionGroup: ... @overload def add_option_group(self, *args: Any, **kwargs: Any) -> OptionGroup: ... - def check_values(self, values: Values, args: List[_Text]) -> Tuple[Values, List[_Text]]: ... + def check_values(self, values: Values, args: List[str]) -> Tuple[Values, List[str]]: ... def disable_interspersed_args(self) -> None: ... def enable_interspersed_args(self) -> None: ... - def error(self, msg: _Text) -> None: ... + def error(self, msg: str) -> None: ... def exit(self, status: int = ..., msg: Optional[str] = ...) -> None: ... - def expand_prog_name(self, s: Optional[_Text]) -> Any: ... + def expand_prog_name(self, s: Optional[str]) -> Any: ... def format_epilog(self, formatter: HelpFormatter) -> Any: ... - def format_help(self, formatter: Optional[HelpFormatter] = ...) -> _Text: ... - def format_option_help(self, formatter: Optional[HelpFormatter] = ...) -> _Text: ... + def format_help(self, formatter: Optional[HelpFormatter] = ...) -> str: ... + def format_option_help(self, formatter: Optional[HelpFormatter] = ...) -> str: ... def get_default_values(self) -> Values: ... - def get_option_group(self, opt_str: _Text) -> Any: ... - def get_prog_name(self) -> _Text: ... - def get_usage(self) -> _Text: ... - def get_version(self) -> _Text: ... + def get_option_group(self, opt_str: str) -> Any: ... + def get_prog_name(self) -> str: ... + def get_usage(self) -> str: ... + def get_version(self) -> str: ... def parse_args( self, args: Optional[Sequence[AnyStr]] = ..., values: Optional[Values] = ... ) -> Tuple[Values, List[AnyStr]]: ... @@ -225,4 +224,4 @@ class OptionParser(OptionContainer): def set_default(self, dest: Any, value: Any) -> None: ... def set_defaults(self, **kwargs: Any) -> None: ... def set_process_default_values(self, process: Any) -> None: ... - def set_usage(self, usage: _Text) -> None: ... + def set_usage(self, usage: str) -> None: ... diff --git a/stdlib/pkgutil.pyi b/stdlib/pkgutil.pyi index 0ccda44c9..583b262d4 100644 --- a/stdlib/pkgutil.pyi +++ b/stdlib/pkgutil.pyi @@ -8,8 +8,6 @@ class ModuleInfo(NamedTuple): name: str ispkg: bool -_ModuleInfoLike = ModuleInfo - def extend_path(path: List[str], name: str) -> List[str]: ... class ImpImporter: @@ -22,11 +20,11 @@ def find_loader(fullname: str) -> Optional[Loader]: ... def get_importer(path_item: str) -> Optional[PathEntryFinder]: ... def get_loader(module_or_name: str) -> Loader: ... def iter_importers(fullname: str = ...) -> Iterator[Union[MetaPathFinder, PathEntryFinder]]: ... -def iter_modules(path: Optional[Iterable[str]] = ..., prefix: str = ...) -> Iterator[_ModuleInfoLike]: ... +def iter_modules(path: Optional[Iterable[str]] = ..., prefix: str = ...) -> Iterator[ModuleInfo]: ... def read_code(stream: SupportsRead[bytes]) -> Any: ... # undocumented def walk_packages( path: Optional[Iterable[str]] = ..., prefix: str = ..., onerror: Optional[Callable[[str], None]] = ... -) -> Iterator[_ModuleInfoLike]: ... +) -> Iterator[ModuleInfo]: ... def get_data(package: str, resource: str) -> Optional[bytes]: ... if sys.version_info >= (3, 9): diff --git a/stdlib/plistlib.pyi b/stdlib/plistlib.pyi index e31078ad5..c74d0d8d5 100644 --- a/stdlib/plistlib.pyi +++ b/stdlib/plistlib.pyi @@ -1,6 +1,6 @@ import sys from enum import Enum -from typing import IO, Any, Dict as DictT, Mapping, MutableMapping, Optional, Text, Type, Union +from typing import IO, Any, Dict as DictT, Mapping, MutableMapping, Optional, Type, Union class PlistFormat(Enum): FMT_XML: int @@ -9,8 +9,6 @@ class PlistFormat(Enum): FMT_XML = PlistFormat.FMT_XML FMT_BINARY = PlistFormat.FMT_BINARY -_Path = Union[str, Text] - if sys.version_info >= (3, 9): def load(fp: IO[bytes], *, fmt: Optional[PlistFormat] = ..., dict_type: Type[MutableMapping[str, Any]] = ...) -> Any: ... def loads(value: bytes, *, fmt: Optional[PlistFormat] = ..., dict_type: Type[MutableMapping[str, Any]] = ...) -> Any: ... @@ -37,8 +35,8 @@ def dump( def dumps(value: Mapping[str, Any], *, fmt: PlistFormat = ..., skipkeys: bool = ..., sort_keys: bool = ...) -> bytes: ... if sys.version_info < (3, 9): - def readPlist(pathOrFile: Union[_Path, IO[bytes]]) -> Any: ... - def writePlist(value: Mapping[str, Any], pathOrFile: Union[_Path, IO[bytes]]) -> None: ... + def readPlist(pathOrFile: Union[str, IO[bytes]]) -> Any: ... + def writePlist(value: Mapping[str, Any], pathOrFile: Union[str, IO[bytes]]) -> None: ... def readPlistFromBytes(data: bytes) -> Any: ... def writePlistToBytes(value: Mapping[str, Any]) -> bytes: ... diff --git a/stdlib/poplib.pyi b/stdlib/poplib.pyi index e08000927..8f09c59f9 100644 --- a/stdlib/poplib.pyi +++ b/stdlib/poplib.pyi @@ -1,6 +1,6 @@ import socket import ssl -from typing import Any, BinaryIO, Dict, List, Optional, Pattern, Text, Tuple, overload +from typing import Any, BinaryIO, Dict, List, Optional, Pattern, Tuple, overload _LongResp = Tuple[bytes, List[bytes], int] @@ -13,17 +13,17 @@ LF: bytes CRLF: bytes class POP3: - encoding: Text - host: Text + encoding: str + host: str port: int sock: socket.socket file: BinaryIO welcome: bytes - def __init__(self, host: Text, port: int = ..., timeout: float = ...) -> None: ... + def __init__(self, host: str, port: int = ..., timeout: float = ...) -> None: ... def getwelcome(self) -> bytes: ... def set_debuglevel(self, level: int) -> None: ... - def user(self, user: Text) -> bytes: ... - def pass_(self, pswd: Text) -> bytes: ... + def user(self, user: str) -> bytes: ... + def pass_(self, pswd: str) -> bytes: ... def stat(self) -> Tuple[int, int]: ... def list(self, which: Optional[Any] = ...) -> _LongResp: ... def retr(self, which: Any) -> _LongResp: ... @@ -32,25 +32,25 @@ class POP3: def rset(self) -> bytes: ... def quit(self) -> bytes: ... def close(self) -> None: ... - def rpop(self, user: Text) -> bytes: ... - timestamp: Pattern[Text] - def apop(self, user: Text, password: Text) -> bytes: ... + def rpop(self, user: str) -> bytes: ... + timestamp: Pattern[str] + def apop(self, user: str, password: str) -> bytes: ... def top(self, which: Any, howmuch: int) -> _LongResp: ... @overload def uidl(self) -> _LongResp: ... @overload def uidl(self, which: Any) -> bytes: ... def utf8(self) -> bytes: ... - def capa(self) -> Dict[Text, List[Text]]: ... + def capa(self) -> Dict[str, List[str]]: ... def stls(self, context: Optional[ssl.SSLContext] = ...) -> bytes: ... class POP3_SSL(POP3): def __init__( self, - host: Text, + host: str, port: int = ..., - keyfile: Optional[Text] = ..., - certfile: Optional[Text] = ..., + keyfile: Optional[str] = ..., + certfile: Optional[str] = ..., timeout: float = ..., context: Optional[ssl.SSLContext] = ..., ) -> None: ... diff --git a/stdlib/rlcompleter.pyi b/stdlib/rlcompleter.pyi index 84e76c771..8afb5b1ef 100644 --- a/stdlib/rlcompleter.pyi +++ b/stdlib/rlcompleter.pyi @@ -1,7 +1,5 @@ from typing import Any, Dict, Optional -_Text = str - class Completer: def __init__(self, namespace: Optional[Dict[str, Any]] = ...) -> None: ... - def complete(self, text: _Text, state: int) -> Optional[str]: ... + def complete(self, text: str, state: int) -> Optional[str]: ... diff --git a/stdlib/shutil.pyi b/stdlib/shutil.pyi index c972a62a6..ad077df80 100644 --- a/stdlib/shutil.pyi +++ b/stdlib/shutil.pyi @@ -3,8 +3,7 @@ import sys from _typeshed import StrPath, SupportsRead, SupportsWrite from typing import Any, AnyStr, Callable, Iterable, List, NamedTuple, Optional, Sequence, Set, Tuple, TypeVar, Union, overload -_AnyStr = str -_AnyPath = TypeVar("_AnyPath", str, os.PathLike[str]) +_PathT = TypeVar("_PathT", str, os.PathLike[str]) # Return value of some functions that may either return a path-like object that was passed in or # a string _PathReturn = Any @@ -17,12 +16,12 @@ class ReadError(OSError): ... class RegistryError(Exception): ... def copyfileobj(fsrc: SupportsRead[AnyStr], fdst: SupportsWrite[AnyStr], length: int = ...) -> None: ... -def copyfile(src: StrPath, dst: _AnyPath, *, follow_symlinks: bool = ...) -> _AnyPath: ... +def copyfile(src: StrPath, dst: _PathT, *, follow_symlinks: bool = ...) -> _PathT: ... def copymode(src: StrPath, dst: StrPath, *, follow_symlinks: bool = ...) -> None: ... def copystat(src: StrPath, dst: StrPath, *, follow_symlinks: bool = ...) -> None: ... def copy(src: StrPath, dst: StrPath, *, follow_symlinks: bool = ...) -> _PathReturn: ... def copy2(src: StrPath, dst: StrPath, *, follow_symlinks: bool = ...) -> _PathReturn: ... -def ignore_patterns(*patterns: StrPath) -> Callable[[Any, List[_AnyStr]], Set[_AnyStr]]: ... +def ignore_patterns(*patterns: StrPath) -> Callable[[Any, List[str]], Set[str]]: ... if sys.version_info >= (3, 8): def copytree( @@ -76,7 +75,7 @@ else: def which(cmd: StrPath, mode: int = ..., path: Optional[StrPath] = ...) -> Optional[str]: ... def make_archive( - base_name: _AnyStr, + base_name: str, format: str, root_dir: Optional[StrPath] = ..., base_dir: Optional[StrPath] = ..., @@ -85,7 +84,7 @@ def make_archive( owner: Optional[str] = ..., group: Optional[str] = ..., logger: Optional[Any] = ..., -) -> _AnyStr: ... +) -> str: ... def get_archive_formats() -> List[Tuple[str, str]]: ... def register_archive_format( name: str, diff --git a/stdlib/sndhdr.pyi b/stdlib/sndhdr.pyi index f3b3b43b7..b86b3b16e 100644 --- a/stdlib/sndhdr.pyi +++ b/stdlib/sndhdr.pyi @@ -8,7 +8,5 @@ class SndHeaders(NamedTuple): nframes: int sampwidth: Union[int, str] -_SndHeaders = SndHeaders - -def what(filename: AnyPath) -> Optional[_SndHeaders]: ... -def whathdr(filename: AnyPath) -> Optional[_SndHeaders]: ... +def what(filename: AnyPath) -> Optional[SndHeaders]: ... +def whathdr(filename: AnyPath) -> Optional[SndHeaders]: ... diff --git a/stdlib/sre_compile.pyi b/stdlib/sre_compile.pyi index 86b636679..492a194f1 100644 --- a/stdlib/sre_compile.pyi +++ b/stdlib/sre_compile.pyi @@ -19,8 +19,5 @@ from typing import Any, List, Pattern, Union MAXCODE: int def dis(code: List[_NamedIntConstant]) -> None: ... - -_IsStringType = bool - -def isstring(obj: Any) -> _IsStringType: ... +def isstring(obj: Any) -> bool: ... def compile(p: Union[str, bytes, SubPattern], flags: int = ...) -> Pattern[Any]: ... diff --git a/stdlib/ssl.pyi b/stdlib/ssl.pyi index 503cadfeb..4164903e2 100644 --- a/stdlib/ssl.pyi +++ b/stdlib/ssl.pyi @@ -12,8 +12,7 @@ _PeerCertRetType = Union[_PeerCertRetDictType, bytes, None] _EnumRetType = List[Tuple[bytes, str, Union[Set[str], bool]]] _PasswordType = Union[Callable[[], Union[str, bytes]], str, bytes] -_SC1ArgT = Union[SSLSocket, SSLObject] -_SrvnmeCbType = Callable[[_SC1ArgT, Optional[str], SSLSocket], Optional[int]] +_SrvnmeCbType = Callable[[Union[SSLSocket, SSLObject], Optional[str], SSLSocket], Optional[int]] class SSLError(OSError): library: str diff --git a/stdlib/struct.pyi b/stdlib/struct.pyi index 940924bcc..ddda12025 100644 --- a/stdlib/struct.pyi +++ b/stdlib/struct.pyi @@ -1,20 +1,15 @@ import sys -from array import array -from mmap import mmap -from typing import Any, Iterator, Text, Tuple, Union +from _typeshed import ReadableBuffer, WriteableBuffer +from typing import Any, Iterator, Tuple, Union class error(Exception): ... -_FmtType = Union[bytes, Text] -_BufferType = Union[array[int], bytes, bytearray, memoryview, mmap] -_WriteBufferType = Union[array[Any], bytearray, memoryview, mmap] - -def pack(fmt: _FmtType, *v: Any) -> bytes: ... -def pack_into(fmt: _FmtType, buffer: _WriteBufferType, offset: int, *v: Any) -> None: ... -def unpack(__format: _FmtType, __buffer: _BufferType) -> Tuple[Any, ...]: ... -def unpack_from(__format: _FmtType, buffer: _BufferType, offset: int = ...) -> Tuple[Any, ...]: ... -def iter_unpack(__format: _FmtType, __buffer: _BufferType) -> Iterator[Tuple[Any, ...]]: ... -def calcsize(__format: _FmtType) -> int: ... +def pack(fmt: Union[str, bytes], *v: Any) -> bytes: ... +def pack_into(fmt: Union[str, bytes], buffer: WriteableBuffer, offset: int, *v: Any) -> None: ... +def unpack(__format: Union[str, bytes], __buffer: ReadableBuffer) -> Tuple[Any, ...]: ... +def unpack_from(__format: Union[str, bytes], buffer: ReadableBuffer, offset: int = ...) -> Tuple[Any, ...]: ... +def iter_unpack(__format: Union[str, bytes], __buffer: ReadableBuffer) -> Iterator[Tuple[Any, ...]]: ... +def calcsize(__format: Union[str, bytes]) -> int: ... class Struct: if sys.version_info >= (3, 7): @@ -22,9 +17,9 @@ class Struct: else: format: bytes size: int - def __init__(self, format: _FmtType) -> None: ... + def __init__(self, format: Union[str, bytes]) -> None: ... def pack(self, *v: Any) -> bytes: ... - def pack_into(self, buffer: _WriteBufferType, offset: int, *v: Any) -> None: ... - def unpack(self, __buffer: _BufferType) -> Tuple[Any, ...]: ... - def unpack_from(self, buffer: _BufferType, offset: int = ...) -> Tuple[Any, ...]: ... - def iter_unpack(self, __buffer: _BufferType) -> Iterator[Tuple[Any, ...]]: ... + def pack_into(self, buffer: WriteableBuffer, offset: int, *v: Any) -> None: ... + def unpack(self, __buffer: ReadableBuffer) -> Tuple[Any, ...]: ... + def unpack_from(self, buffer: ReadableBuffer, offset: int = ...) -> Tuple[Any, ...]: ... + def iter_unpack(self, __buffer: ReadableBuffer) -> Iterator[Tuple[Any, ...]]: ... diff --git a/stdlib/timeit.pyi b/stdlib/timeit.pyi index 0d185e966..18ab9bd93 100644 --- a/stdlib/timeit.pyi +++ b/stdlib/timeit.pyi @@ -1,14 +1,13 @@ -from typing import IO, Any, Callable, Dict, List, Optional, Sequence, Text, Tuple, Union +from typing import IO, Any, Callable, Dict, List, Optional, Sequence, Tuple, Union -_str = Union[str, Text] _Timer = Callable[[], float] -_stmt = Union[_str, Callable[[], Any]] +_Stmt = Union[str, Callable[[], Any]] default_timer: _Timer class Timer: def __init__( - self, stmt: _stmt = ..., setup: _stmt = ..., timer: _Timer = ..., globals: Optional[Dict[str, Any]] = ... + self, stmt: _Stmt = ..., setup: _Stmt = ..., timer: _Timer = ..., globals: Optional[Dict[str, Any]] = ... ) -> None: ... def print_exc(self, file: Optional[IO[str]] = ...) -> None: ... def timeit(self, number: int = ...) -> float: ... @@ -16,11 +15,11 @@ class Timer: def autorange(self, callback: Optional[Callable[[int, float], Any]] = ...) -> Tuple[int, float]: ... def timeit( - stmt: _stmt = ..., setup: _stmt = ..., timer: _Timer = ..., number: int = ..., globals: Optional[Dict[str, Any]] = ... + stmt: _Stmt = ..., setup: _Stmt = ..., timer: _Timer = ..., number: int = ..., globals: Optional[Dict[str, Any]] = ... ) -> float: ... def repeat( - stmt: _stmt = ..., - setup: _stmt = ..., + stmt: _Stmt = ..., + setup: _Stmt = ..., timer: _Timer = ..., repeat: int = ..., number: int = ..., diff --git a/stdlib/xml/dom/minidom.pyi b/stdlib/xml/dom/minidom.pyi index 67e9b1189..90396299e 100644 --- a/stdlib/xml/dom/minidom.pyi +++ b/stdlib/xml/dom/minidom.pyi @@ -1,13 +1,13 @@ import sys import xml.dom -from typing import IO, Any, Optional, Text as _Text, TypeVar, Union +from typing import IO, Any, Optional, TypeVar, Union from xml.dom.xmlbuilder import DocumentLS, DOMImplementationLS from xml.sax.xmlreader import XMLReader _T = TypeVar("_T") def parse(file: Union[str, IO[Any]], parser: Optional[XMLReader] = ..., bufsize: Optional[int] = ...): ... -def parseString(string: Union[bytes, _Text], parser: Optional[XMLReader] = ...): ... +def parseString(string: Union[str, bytes], parser: Optional[XMLReader] = ...): ... def getDOMImplementation(features=...): ... class Node(xml.dom.Node): diff --git a/stdlib/xml/etree/ElementTree.pyi b/stdlib/xml/etree/ElementTree.pyi index 0ac37e00c..09bd32f01 100644 --- a/stdlib/xml/etree/ElementTree.pyi +++ b/stdlib/xml/etree/ElementTree.pyi @@ -14,7 +14,6 @@ from typing import ( MutableSequence, Optional, Sequence, - Text, Tuple, TypeVar, Union, @@ -22,6 +21,9 @@ from typing import ( ) from typing_extensions import Literal +_T = TypeVar("_T") +_File = Union[AnyPath, FileDescriptor, IO[Any]] + VERSION: str class ParseError(SyntaxError): @@ -30,34 +32,13 @@ class ParseError(SyntaxError): def iselement(element: object) -> bool: ... -_T = TypeVar("_T") - -# Type for parser inputs. Parser will accept any unicode/str/bytes and coerce, -# and this is true in py2 and py3 (even fromstringlist() in python3 can be -# called with a heterogeneous list) -_parser_input_type = Union[bytes, Text] - -# Type for individual tag/attr/ns/text values in args to most functions. -# In py2, the library accepts str or unicode everywhere and coerces -# aggressively. -# In py3, bytes is not coerced to str and so use of bytes is probably an error, -# so we exclude it. (why? the parser never produces bytes when it parses XML, -# so e.g., element.get(b'name') will always return None for parsed XML, even if -# there is a 'name' attribute.) -_str_argument_type = Union[str, Text] - -# Type for return values from individual tag/attr/text values -_str_result_type = str - -_file_or_filename = Union[AnyPath, FileDescriptor, IO[Any]] - if sys.version_info >= (3, 8): @overload def canonicalize( - xml_data: Optional[_parser_input_type] = ..., + xml_data: Optional[Union[str, bytes]] = ..., *, out: None = ..., - from_file: Optional[_file_or_filename] = ..., + from_file: Optional[_File] = ..., with_comments: bool = ..., strip_text: bool = ..., rewrite_prefixes: bool = ..., @@ -68,10 +49,10 @@ if sys.version_info >= (3, 8): ) -> str: ... @overload def canonicalize( - xml_data: Optional[_parser_input_type] = ..., + xml_data: Optional[Union[str, bytes]] = ..., *, out: SupportsWrite[str], - from_file: Optional[_file_or_filename] = ..., + from_file: Optional[_File] = ..., with_comments: bool = ..., strip_text: bool = ..., rewrite_prefixes: bool = ..., @@ -82,51 +63,33 @@ if sys.version_info >= (3, 8): ) -> None: ... class Element(MutableSequence[Element]): - tag: _str_result_type - attrib: Dict[_str_result_type, _str_result_type] - text: Optional[_str_result_type] - tail: Optional[_str_result_type] - def __init__( - self, - tag: Union[_str_argument_type, Callable[..., Element]], - attrib: Dict[_str_argument_type, _str_argument_type] = ..., - **extra: _str_argument_type, - ) -> None: ... + tag: str + attrib: Dict[str, str] + text: Optional[str] + tail: Optional[str] + def __init__(self, tag: Union[str, Callable[..., Element]], attrib: Dict[str, str] = ..., **extra: str) -> None: ... def append(self, __subelement: Element) -> None: ... def clear(self) -> None: ... def extend(self, __elements: Iterable[Element]) -> None: ... - def find( - self, path: _str_argument_type, namespaces: Optional[Dict[_str_argument_type, _str_argument_type]] = ... - ) -> Optional[Element]: ... - def findall( - self, path: _str_argument_type, namespaces: Optional[Dict[_str_argument_type, _str_argument_type]] = ... - ) -> List[Element]: ... + def find(self, path: str, namespaces: Optional[Dict[str, str]] = ...) -> Optional[Element]: ... + def findall(self, path: str, namespaces: Optional[Dict[str, str]] = ...) -> List[Element]: ... @overload - def findtext( - self, - path: _str_argument_type, - default: None = ..., - namespaces: Optional[Dict[_str_argument_type, _str_argument_type]] = ..., - ) -> Optional[_str_result_type]: ... + def findtext(self, path: str, default: None = ..., namespaces: Optional[Dict[str, str]] = ...) -> Optional[str]: ... @overload - def findtext( - self, path: _str_argument_type, default: _T, namespaces: Optional[Dict[_str_argument_type, _str_argument_type]] = ... - ) -> Union[_T, _str_result_type]: ... + def findtext(self, path: str, default: _T, namespaces: Optional[Dict[str, str]] = ...) -> Union[_T, str]: ... @overload - def get(self, key: _str_argument_type, default: None = ...) -> Optional[_str_result_type]: ... + def get(self, key: str, default: None = ...) -> Optional[str]: ... @overload - def get(self, key: _str_argument_type, default: _T) -> Union[_str_result_type, _T]: ... + def get(self, key: str, default: _T) -> Union[str, _T]: ... def insert(self, __index: int, __subelement: Element) -> None: ... - def items(self) -> ItemsView[_str_result_type, _str_result_type]: ... - def iter(self, tag: Optional[_str_argument_type] = ...) -> Generator[Element, None, None]: ... - def iterfind( - self, path: _str_argument_type, namespaces: Optional[Dict[_str_argument_type, _str_argument_type]] = ... - ) -> Generator[Element, None, None]: ... - def itertext(self) -> Generator[_str_result_type, None, None]: ... - def keys(self) -> KeysView[_str_result_type]: ... - def makeelement(self, __tag: _str_argument_type, __attrib: Dict[_str_argument_type, _str_argument_type]) -> Element: ... + def items(self) -> ItemsView[str, str]: ... + def iter(self, tag: Optional[str] = ...) -> Generator[Element, None, None]: ... + def iterfind(self, path: str, namespaces: Optional[Dict[str, str]] = ...) -> Generator[Element, None, None]: ... + def itertext(self) -> Generator[str, None, None]: ... + def keys(self) -> KeysView[str]: ... + def makeelement(self, __tag: str, __attrib: Dict[str, str]) -> Element: ... def remove(self, __subelement: Element) -> None: ... - def set(self, __key: _str_argument_type, __value: _str_argument_type) -> None: ... + def set(self, __key: str, __value: str) -> None: ... def __delitem__(self, i: Union[int, slice]) -> None: ... @overload def __getitem__(self, i: int) -> Element: ... @@ -139,63 +102,45 @@ class Element(MutableSequence[Element]): def __setitem__(self, s: slice, o: Iterable[Element]) -> None: ... if sys.version_info < (3, 9): def getchildren(self) -> List[Element]: ... - def getiterator(self, tag: Optional[_str_argument_type] = ...) -> List[Element]: ... + def getiterator(self, tag: Optional[str] = ...) -> List[Element]: ... -def SubElement( - parent: Element, - tag: _str_argument_type, - attrib: Dict[_str_argument_type, _str_argument_type] = ..., - **extra: _str_argument_type, -) -> Element: ... -def Comment(text: Optional[_str_argument_type] = ...) -> Element: ... -def ProcessingInstruction(target: _str_argument_type, text: Optional[_str_argument_type] = ...) -> Element: ... +def SubElement(parent: Element, tag: str, attrib: Dict[str, str] = ..., **extra: str) -> Element: ... +def Comment(text: Optional[str] = ...) -> Element: ... +def ProcessingInstruction(target: str, text: Optional[str] = ...) -> Element: ... PI: Callable[..., Element] class QName: text: str - def __init__(self, text_or_uri: _str_argument_type, tag: Optional[_str_argument_type] = ...) -> None: ... + def __init__(self, text_or_uri: str, tag: Optional[str] = ...) -> None: ... class ElementTree: - def __init__(self, element: Optional[Element] = ..., file: Optional[_file_or_filename] = ...) -> None: ... + def __init__(self, element: Optional[Element] = ..., file: Optional[_File] = ...) -> None: ... def getroot(self) -> Element: ... - def parse(self, source: _file_or_filename, parser: Optional[XMLParser] = ...) -> Element: ... - def iter(self, tag: Optional[_str_argument_type] = ...) -> Generator[Element, None, None]: ... + def parse(self, source: _File, parser: Optional[XMLParser] = ...) -> Element: ... + def iter(self, tag: Optional[str] = ...) -> Generator[Element, None, None]: ... if sys.version_info < (3, 9): - def getiterator(self, tag: Optional[_str_argument_type] = ...) -> List[Element]: ... - def find( - self, path: _str_argument_type, namespaces: Optional[Dict[_str_argument_type, _str_argument_type]] = ... - ) -> Optional[Element]: ... + def getiterator(self, tag: Optional[str] = ...) -> List[Element]: ... + def find(self, path: str, namespaces: Optional[Dict[str, str]] = ...) -> Optional[Element]: ... @overload - def findtext( - self, - path: _str_argument_type, - default: None = ..., - namespaces: Optional[Dict[_str_argument_type, _str_argument_type]] = ..., - ) -> Optional[_str_result_type]: ... + def findtext(self, path: str, default: None = ..., namespaces: Optional[Dict[str, str]] = ...) -> Optional[str]: ... @overload - def findtext( - self, path: _str_argument_type, default: _T, namespaces: Optional[Dict[_str_argument_type, _str_argument_type]] = ... - ) -> Union[_T, _str_result_type]: ... - def findall( - self, path: _str_argument_type, namespaces: Optional[Dict[_str_argument_type, _str_argument_type]] = ... - ) -> List[Element]: ... - def iterfind( - self, path: _str_argument_type, namespaces: Optional[Dict[_str_argument_type, _str_argument_type]] = ... - ) -> Generator[Element, None, None]: ... + def findtext(self, path: str, default: _T, namespaces: Optional[Dict[str, str]] = ...) -> Union[_T, str]: ... + def findall(self, path: str, namespaces: Optional[Dict[str, str]] = ...) -> List[Element]: ... + def iterfind(self, path: str, namespaces: Optional[Dict[str, str]] = ...) -> Generator[Element, None, None]: ... def write( self, - file_or_filename: _file_or_filename, + file_or_filename: _File, encoding: Optional[str] = ..., xml_declaration: Optional[bool] = ..., - default_namespace: Optional[_str_argument_type] = ..., + default_namespace: Optional[str] = ..., method: Optional[str] = ..., *, short_empty_elements: bool = ..., ) -> None: ... - def write_c14n(self, file: _file_or_filename) -> None: ... + def write_c14n(self, file: _File) -> None: ... -def register_namespace(prefix: _str_argument_type, uri: _str_argument_type) -> None: ... +def register_namespace(prefix: str, uri: str) -> None: ... if sys.version_info >= (3, 8): @overload @@ -205,7 +150,7 @@ if sys.version_info >= (3, 8): method: Optional[str] = ..., *, xml_declaration: Optional[bool] = ..., - default_namespace: Optional[_str_argument_type] = ..., + default_namespace: Optional[str] = ..., short_empty_elements: bool = ..., ) -> bytes: ... @overload @@ -215,7 +160,7 @@ if sys.version_info >= (3, 8): method: Optional[str] = ..., *, xml_declaration: Optional[bool] = ..., - default_namespace: Optional[_str_argument_type] = ..., + default_namespace: Optional[str] = ..., short_empty_elements: bool = ..., ) -> str: ... @overload @@ -225,7 +170,7 @@ if sys.version_info >= (3, 8): method: Optional[str] = ..., *, xml_declaration: Optional[bool] = ..., - default_namespace: Optional[_str_argument_type] = ..., + default_namespace: Optional[str] = ..., short_empty_elements: bool = ..., ) -> Any: ... @overload @@ -235,7 +180,7 @@ if sys.version_info >= (3, 8): method: Optional[str] = ..., *, xml_declaration: Optional[bool] = ..., - default_namespace: Optional[_str_argument_type] = ..., + default_namespace: Optional[str] = ..., short_empty_elements: bool = ..., ) -> List[bytes]: ... @overload @@ -245,7 +190,7 @@ if sys.version_info >= (3, 8): method: Optional[str] = ..., *, xml_declaration: Optional[bool] = ..., - default_namespace: Optional[_str_argument_type] = ..., + default_namespace: Optional[str] = ..., short_empty_elements: bool = ..., ) -> List[str]: ... @overload @@ -255,7 +200,7 @@ if sys.version_info >= (3, 8): method: Optional[str] = ..., *, xml_declaration: Optional[bool] = ..., - default_namespace: Optional[_str_argument_type] = ..., + default_namespace: Optional[str] = ..., short_empty_elements: bool = ..., ) -> List[Any]: ... @@ -288,9 +233,9 @@ def dump(elem: Element) -> None: ... if sys.version_info >= (3, 9): def indent(tree: Union[Element, ElementTree], space: str = ..., level: int = ...) -> None: ... -def parse(source: _file_or_filename, parser: Optional[XMLParser] = ...) -> ElementTree: ... +def parse(source: _File, parser: Optional[XMLParser] = ...) -> ElementTree: ... def iterparse( - source: _file_or_filename, events: Optional[Sequence[str]] = ..., parser: Optional[XMLParser] = ... + source: _File, events: Optional[Sequence[str]] = ..., parser: Optional[XMLParser] = ... ) -> Iterator[Tuple[str, Any]]: ... class XMLPullParser: @@ -299,13 +244,13 @@ class XMLPullParser: def close(self) -> None: ... def read_events(self) -> Iterator[Tuple[str, Element]]: ... -def XML(text: _parser_input_type, parser: Optional[XMLParser] = ...) -> Element: ... -def XMLID(text: _parser_input_type, parser: Optional[XMLParser] = ...) -> Tuple[Element, Dict[_str_result_type, Element]]: ... +def XML(text: Union[str, bytes], parser: Optional[XMLParser] = ...) -> Element: ... +def XMLID(text: Union[str, bytes], parser: Optional[XMLParser] = ...) -> Tuple[Element, Dict[str, Element]]: ... # This is aliased to XML in the source. fromstring = XML -def fromstringlist(sequence: Sequence[_parser_input_type], parser: Optional[XMLParser] = ...) -> Element: ... +def fromstringlist(sequence: Sequence[Union[str, bytes]], parser: Optional[XMLParser] = ...) -> Element: ... # This type is both not precise enough and too precise. The TreeBuilder # requires the elementfactory to accept tag and attrs in its args and produce @@ -321,9 +266,9 @@ _ElementFactory = Callable[[Any, Dict[Any, Any]], Element] class TreeBuilder: def __init__(self, element_factory: Optional[_ElementFactory] = ...) -> None: ... def close(self) -> Element: ... - def data(self, __data: _parser_input_type) -> None: ... - def start(self, __tag: _parser_input_type, __attrs: Dict[_parser_input_type, _parser_input_type]) -> Element: ... - def end(self, __tag: _parser_input_type) -> Element: ... + def data(self, __data: Union[str, bytes]) -> None: ... + def start(self, __tag: Union[str, bytes], __attrs: Dict[Union[str, bytes], Union[str, bytes]]) -> Element: ... + def end(self, __tag: Union[str, bytes]) -> Element: ... if sys.version_info >= (3, 8): class C14NWriterTarget: @@ -352,4 +297,4 @@ class XMLParser: def __init__(self, html: int = ..., target: Any = ..., encoding: Optional[str] = ...) -> None: ... def doctype(self, __name: str, __pubid: str, __system: str) -> None: ... def close(self) -> Any: ... - def feed(self, __data: _parser_input_type) -> None: ... + def feed(self, __data: Union[str, bytes]) -> None: ... diff --git a/stdlib/zipfile.pyi b/stdlib/zipfile.pyi index 8653eebe0..23d5e3b45 100644 --- a/stdlib/zipfile.pyi +++ b/stdlib/zipfile.pyi @@ -2,10 +2,9 @@ import io import sys from _typeshed import StrPath from types import TracebackType -from typing import IO, Any, Callable, Dict, Iterable, Iterator, List, Optional, Protocol, Sequence, Text, Tuple, Type, Union +from typing import IO, Any, Callable, Dict, Iterable, Iterator, List, Optional, Protocol, Sequence, Tuple, Type, Union -_SZI = Union[Text, ZipInfo] -_DT = Tuple[int, int, int, int, int, int] +_DateTuple = Tuple[int, int, int, int, int, int] class BadZipFile(Exception): ... @@ -47,12 +46,12 @@ class _Writer(Protocol): def write(self, __s: str) -> Any: ... class ZipFile: - filename: Optional[Text] + filename: Optional[str] debug: int comment: bytes filelist: List[ZipInfo] fp: Optional[IO[bytes]] - NameToInfo: Dict[Text, ZipInfo] + NameToInfo: Dict[str, ZipInfo] start_dir: int # undocumented if sys.version_info >= (3, 8): def __init__( @@ -76,24 +75,26 @@ class ZipFile: ) -> None: ... else: def __init__( - self, file: Union[StrPath, IO[bytes]], mode: Text = ..., compression: int = ..., allowZip64: bool = ... + self, file: Union[StrPath, IO[bytes]], mode: str = ..., compression: int = ..., allowZip64: bool = ... ) -> None: ... def __enter__(self) -> ZipFile: ... def __exit__( self, exc_type: Optional[Type[BaseException]], exc_val: Optional[BaseException], exc_tb: Optional[TracebackType] ) -> None: ... def close(self) -> None: ... - def getinfo(self, name: Text) -> ZipInfo: ... + def getinfo(self, name: str) -> ZipInfo: ... def infolist(self) -> List[ZipInfo]: ... - def namelist(self) -> List[Text]: ... - def open(self, name: _SZI, mode: Text = ..., pwd: Optional[bytes] = ..., *, force_zip64: bool = ...) -> IO[bytes]: ... - def extract(self, member: _SZI, path: Optional[StrPath] = ..., pwd: Optional[bytes] = ...) -> str: ... + def namelist(self) -> List[str]: ... + def open( + self, name: Union[str, ZipInfo], mode: str = ..., pwd: Optional[bytes] = ..., *, force_zip64: bool = ... + ) -> IO[bytes]: ... + def extract(self, member: Union[str, ZipInfo], path: Optional[StrPath] = ..., pwd: Optional[bytes] = ...) -> str: ... def extractall( - self, path: Optional[StrPath] = ..., members: Optional[Iterable[Text]] = ..., pwd: Optional[bytes] = ... + self, path: Optional[StrPath] = ..., members: Optional[Iterable[str]] = ..., pwd: Optional[bytes] = ... ) -> None: ... def printdir(self, file: Optional[_Writer] = ...) -> None: ... def setpassword(self, pwd: bytes) -> None: ... - def read(self, name: _SZI, pwd: Optional[bytes] = ...) -> bytes: ... + def read(self, name: Union[str, ZipInfo], pwd: Optional[bytes] = ...) -> bytes: ... def testzip(self) -> Optional[str]: ... if sys.version_info >= (3, 7): def write( @@ -108,13 +109,15 @@ class ZipFile: if sys.version_info >= (3, 7): def writestr( self, - zinfo_or_arcname: _SZI, + zinfo_or_arcname: Union[str, ZipInfo], data: Union[bytes, str], compress_type: Optional[int] = ..., compresslevel: Optional[int] = ..., ) -> None: ... else: - def writestr(self, zinfo_or_arcname: _SZI, data: Union[bytes, str], compress_type: Optional[int] = ...) -> None: ... + def writestr( + self, zinfo_or_arcname: Union[str, ZipInfo], data: Union[bytes, str], compress_type: Optional[int] = ... + ) -> None: ... class PyZipFile(ZipFile): def __init__( @@ -123,8 +126,8 @@ class PyZipFile(ZipFile): def writepy(self, pathname: str, basename: str = ..., filterfunc: Optional[Callable[[str], bool]] = ...) -> None: ... class ZipInfo: - filename: Text - date_time: _DT + filename: str + date_time: _DateTuple compress_type: int comment: bytes extra: bytes @@ -140,7 +143,7 @@ class ZipInfo: CRC: int compress_size: int file_size: int - def __init__(self, filename: Optional[Text] = ..., date_time: Optional[_DT] = ...) -> None: ... + def __init__(self, filename: Optional[str] = ..., date_time: Optional[_DateTuple] = ...) -> None: ... if sys.version_info >= (3, 8): @classmethod def from_file(cls, filename: StrPath, arcname: Optional[StrPath] = ..., *, strict_timestamps: bool = ...) -> ZipInfo: ...