From 014265d52e8f3bffa7d005e84f97adbc1ca99984 Mon Sep 17 00:00:00 2001 From: Ali Hamdan Date: Sun, 29 Dec 2024 12:30:44 +0100 Subject: [PATCH 1/2] optparse: Fix `OptionParser` types --- stdlib/optparse.pyi | 33 +++++++++++++++------------------ 1 file changed, 15 insertions(+), 18 deletions(-) diff --git a/stdlib/optparse.pyi b/stdlib/optparse.pyi index 5c70548f9d49..4d32299dda36 100644 --- a/stdlib/optparse.pyi +++ b/stdlib/optparse.pyi @@ -1,8 +1,8 @@ import builtins -from _typeshed import Incomplete, MaybeNone +from _typeshed import Incomplete, 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__ = [ @@ -254,13 +254,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 @@ -279,14 +279,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: ... From eed2096bd964e04740f431ba4d6a6d186ea413b9 Mon Sep 17 00:00:00 2001 From: Ali Hamdan Date: Mon, 30 Dec 2024 08:58:08 +0100 Subject: [PATCH 2/2] Remove unused import --- stdlib/optparse.pyi | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/stdlib/optparse.pyi b/stdlib/optparse.pyi index 38858ddf881a..583dd0da009e 100644 --- a/stdlib/optparse.pyi +++ b/stdlib/optparse.pyi @@ -1,5 +1,5 @@ import builtins -from _typeshed import Incomplete, MaybeNone, SupportsWrite +from _typeshed import MaybeNone, SupportsWrite from abc import abstractmethod from collections.abc import Callable, Iterable, Mapping, Sequence from typing import Any, ClassVar, Literal, NoReturn, overload