-
-
Notifications
You must be signed in to change notification settings - Fork 34.1k
Description
argparse.ArgumentParser.add_mutually_exclusive_group() returns an argparse._MutuallyExclusiveGroup instance, but this type is private (underscore-prefixed). This makes it impossible to properly type-annotate code that stores the return value without importing a private symbol.
Motivation
When using type checkers (mypy, ty, pyright), code like:
group = parser.add_argument_group("selection")
add_to: ArgumentParser = group.add_mutually_exclusive_group(required=False)is flagged as a type error because _MutuallyExclusiveGroup is not ArgumentParser, but there's no public type to use instead. The only workaround is importing the private _MutuallyExclusiveGroup.
This is similar to #101503 which requests making the return type of add_subparsers public.
Proposal
Make _MutuallyExclusiveGroup (and possibly _ArgumentGroup) public by removing the underscore prefix, or at minimum export a public type alias.
Metadata
Metadata
Assignees
Labels
Projects
Status