From af00613477cab2a72aabbd29897d64d37f2b949d Mon Sep 17 00:00:00 2001 From: Ali Hamdan Date: Sun, 19 Jan 2025 14:59:14 +0100 Subject: [PATCH] optparse: Fix `OptionParser` types (#13339) --- stdlib/optparse.pyi | 33 +++++++++++++++------------------ 1 file changed, 15 insertions(+), 18 deletions(-) diff --git a/stdlib/optparse.pyi b/stdlib/optparse.pyi index ff5e83cf26db..583dd0da009e 100644 --- a/stdlib/optparse.pyi +++ b/stdlib/optparse.pyi @@ -1,8 +1,8 @@ import builtins -from _typeshed import Incomplete, MaybeNone +from _typeshed import MaybeNone, SupportsWrite from abc import abstractmethod from collections.abc import Callable, Iterable, Mapping, Sequence -from typing import IO, Any, AnyStr, ClassVar, Literal, NoReturn, overload +from typing import Any, ClassVar, Literal, NoReturn, overload from typing_extensions import Self __all__ = [ @@ -274,13 +274,13 @@ class OptionParser(OptionContainer): def _add_version_option(self) -> None: ... def _create_option_list(self) -> None: ... def _get_all_options(self) -> list[Option]: ... - def _get_args(self, args: Iterable[Incomplete]) -> list[Incomplete]: ... + def _get_args(self, args: list[str] | None) -> list[str]: ... def _init_parsing_state(self) -> None: ... def _match_long_opt(self, opt: str) -> str: ... - def _populate_option_list(self, option_list: Iterable[Option], add_help: bool = True) -> None: ... - def _process_args(self, largs: list[Incomplete], rargs: list[Incomplete], values: Values) -> None: ... - def _process_long_opt(self, rargs: list[Incomplete], values) -> None: ... - def _process_short_opts(self, rargs: list[Incomplete], values) -> None: ... + def _populate_option_list(self, option_list: Iterable[Option] | None, add_help: bool = True) -> None: ... + def _process_args(self, largs: list[str], rargs: list[str], values: Values) -> None: ... + def _process_long_opt(self, rargs: list[str], values: Values) -> None: ... + def _process_short_opts(self, rargs: list[str], values: Values) -> None: ... @overload def add_option_group(self, opt_group: OptionGroup, /) -> OptionGroup: ... @overload @@ -299,14 +299,11 @@ class OptionParser(OptionContainer): def get_prog_name(self) -> str: ... def get_usage(self) -> str: ... def get_version(self) -> str: ... - @overload - def parse_args(self, args: None = None, values: Values | None = None) -> tuple[Values, list[str]]: ... - @overload - def parse_args(self, args: Sequence[AnyStr], values: Values | None = None) -> tuple[Values, list[AnyStr]]: ... - def print_usage(self, file: IO[str] | None = None) -> None: ... - def print_help(self, file: IO[str] | None = None) -> None: ... - def print_version(self, file: IO[str] | None = None) -> None: ... - def set_default(self, dest, value) -> None: ... - def set_defaults(self, **kwargs) -> None: ... - def set_process_default_values(self, process) -> None: ... - def set_usage(self, usage: str) -> None: ... + def parse_args(self, args: list[str] | None = None, values: Values | None = None) -> tuple[Values, list[str]]: ... + def print_usage(self, file: SupportsWrite[str] | None = None) -> None: ... + def print_help(self, file: SupportsWrite[str] | None = None) -> None: ... + def print_version(self, file: SupportsWrite[str] | None = None) -> None: ... + def set_default(self, dest: str, value: Any) -> None: ... # default value can be "any" type + def set_defaults(self, **kwargs: Any) -> None: ... # default values can be "any" type + def set_process_default_values(self, process: bool) -> None: ... + def set_usage(self, usage: str | None) -> None: ...