From c6ede41cd0e9073efa8bf8f9e029b7cea00b3c85 Mon Sep 17 00:00:00 2001 From: Jon Dufresne Date: Mon, 4 Jan 2021 06:54:55 -0800 Subject: [PATCH] Correct and update several optparse types (#4897) The first positional argument to HelpFormatter.format_option() and HelpFormatter.format_option_strings() is a Option instance, not an OptionParser. Added some attributes to the Option class: - callback - callback_args - callback_kwargs - help - metavar The OptionParser.option_groups attribute is a list of OptionGroup instances, not OptionParser instances. The method OptionParser.add_option_group() returns a OptionGroup instance (the one created/added), not an OptionParser instance. --- stdlib/2and3/optparse.pyi | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-) diff --git a/stdlib/2and3/optparse.pyi b/stdlib/2and3/optparse.pyi index 8fb468844..3d06ac65e 100644 --- a/stdlib/2and3/optparse.pyi +++ b/stdlib/2and3/optparse.pyi @@ -59,8 +59,8 @@ class HelpFormatter: 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: OptionParser) -> _Text: ... - def format_option_strings(self, option: OptionParser) -> _Text: ... + def format_option(self, option: Option) -> _Text: ... + def format_option_strings(self, option: Option) -> _Text: ... def format_usage(self, usage: Any) -> _Text: ... def indent(self) -> None: ... def set_long_opt_delimiter(self, delim: _Text) -> None: ... @@ -98,6 +98,11 @@ class Option: dest: Optional[_Text] 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: ... def _check_action(self) -> None: ... def _check_callback(self) -> None: ... @@ -109,8 +114,8 @@ class Option: 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: Any, value: Any) -> Any: ... - def convert_value(self, opt: Any, value: Any) -> Any: ... + 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 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: ... @@ -169,7 +174,7 @@ class OptionParser(OptionContainer): epilog: Optional[_Text] formatter: HelpFormatter largs: Optional[List[_Text]] - option_groups: List[OptionParser] + option_groups: List[OptionGroup] option_list: List[Option] process_default_values: Any prog: Optional[_Text] @@ -203,9 +208,9 @@ class OptionParser(OptionContainer): def _process_long_opt(self, rargs: List[Any], values: Any) -> None: ... def _process_short_opts(self, rargs: List[Any], values: Any) -> None: ... @overload - def add_option_group(self, __opt_group: OptionGroup) -> OptionParser: ... + def add_option_group(self, __opt_group: OptionGroup) -> OptionGroup: ... @overload - def add_option_group(self, *args: Any, **kwargs: Any) -> OptionParser: ... + def add_option_group(self, *args: Any, **kwargs: Any) -> OptionGroup: ... def check_values(self, values: Values, args: List[_Text]) -> Tuple[Values, List[_Text]]: ... def disable_interspersed_args(self) -> None: ... def enable_interspersed_args(self) -> None: ...