From fceb3ae2250c39b9f5b2ea72e7088ebce772cfb9 Mon Sep 17 00:00:00 2001 From: Shantanu <12621235+hauntsaninja@users.noreply.github.com> Date: Mon, 5 Jun 2023 23:27:51 -0700 Subject: [PATCH] argparse: improve add_argument_group and add_mutually_exclusive_group (#10262) --- stdlib/argparse.pyi | 21 ++++++++++++++++++--- tests/stubtest_allowlists/py311.txt | 2 +- tests/stubtest_allowlists/py312.txt | 2 +- 3 files changed, 20 insertions(+), 5 deletions(-) diff --git a/stdlib/argparse.pyi b/stdlib/argparse.pyi index c986b9cdb..8e6f9da8e 100644 --- a/stdlib/argparse.pyi +++ b/stdlib/argparse.pyi @@ -97,8 +97,16 @@ class _ActionsContainer: version: str = ..., **kwargs: Any, ) -> Action: ... - def add_argument_group(self, *args: Any, **kwargs: Any) -> _ArgumentGroup: ... - def add_mutually_exclusive_group(self, **kwargs: Any) -> _MutuallyExclusiveGroup: ... + def add_argument_group( + self, + title: str | None = None, + description: str | None = None, + *, + prefix_chars: str = ..., + argument_default: Any = ..., + conflict_handler: str = ..., + ) -> _ArgumentGroup: ... + def add_mutually_exclusive_group(self, *, required: bool = False) -> _MutuallyExclusiveGroup: ... def _add_action(self, action: _ActionT) -> _ActionT: ... def _remove_action(self, action: Action) -> None: ... def _add_container_actions(self, container: _ActionsContainer) -> None: ... @@ -350,7 +358,14 @@ class _ArgumentGroup(_ActionsContainer): title: str | None _group_actions: list[Action] def __init__( - self, container: _ActionsContainer, title: str | None = None, description: str | None = None, **kwargs: Any + self, + container: _ActionsContainer, + title: str | None = None, + description: str | None = None, + *, + prefix_chars: str = ..., + argument_default: Any = ..., + conflict_handler: str = ..., ) -> None: ... # undocumented diff --git a/tests/stubtest_allowlists/py311.txt b/tests/stubtest_allowlists/py311.txt index 767c5a5d5..493b5d261 100644 --- a/tests/stubtest_allowlists/py311.txt +++ b/tests/stubtest_allowlists/py311.txt @@ -12,7 +12,6 @@ _collections_abc.MappingView.__class_getitem__ _collections_abc.ValuesView.__reversed__ _csv.Reader _csv.Writer -argparse._MutuallyExclusiveGroup.add_mutually_exclusive_group bz2.BZ2Decompressor.__init__ # function does not accept parameters but C signature is set configparser.LegacyInterpolation.__init__ configparser.ParsingError.filename @@ -81,6 +80,7 @@ _ast.ImportFrom.level # None on the class, but never None on instances _collections_abc.AsyncGenerator.athrow # async at runtime, deliberately not in the stub, see #7491. Pos-only differences also. _weakref.ProxyType.__reversed__ # Doesn't really exist ast.ImportFrom.level # None on the class, but never None on instances +argparse._MutuallyExclusiveGroup.add_mutually_exclusive_group # deprecated, forwards arguments to super asyncio.base_events.BaseEventLoop.subprocess_exec # BaseEventLoop adds several parameters and stubtest fails on the difference if we add them asyncio.BaseEventLoop.subprocess_exec # BaseEventLoop adds several parameters and stubtest fails on the difference if we add them builtins.property.__set_name__ # Doesn't actually exist diff --git a/tests/stubtest_allowlists/py312.txt b/tests/stubtest_allowlists/py312.txt index 2dd2ea5b4..6cbf66ac1 100644 --- a/tests/stubtest_allowlists/py312.txt +++ b/tests/stubtest_allowlists/py312.txt @@ -267,7 +267,6 @@ _collections_abc.MappingView.__class_getitem__ _collections_abc.ValuesView.__reversed__ _csv.Reader _csv.Writer -argparse._MutuallyExclusiveGroup.add_mutually_exclusive_group configparser.LegacyInterpolation.__init__ enum.Enum.__init__ ftplib.FTP.trust_server_pasv_ipv4_address @@ -330,6 +329,7 @@ os.path.join _ast.ImportFrom.level # None on the class, but never None on instances _collections_abc.AsyncGenerator.athrow # async at runtime, deliberately not in the stub, see #7491. Pos-only differences also. _weakref.ProxyType.__reversed__ # Doesn't really exist +argparse._MutuallyExclusiveGroup.add_mutually_exclusive_group # deprecated, forwards arguments to super ast.ImportFrom.level # None on the class, but never None on instances asyncio.base_events.BaseEventLoop.subprocess_exec # BaseEventLoop adds several parameters and stubtest fails on the difference if we add them asyncio.BaseEventLoop.subprocess_exec # BaseEventLoop adds several parameters and stubtest fails on the difference if we add them