-
-
Notifications
You must be signed in to change notification settings - Fork 34.7k
Make _MutuallyExclusiveGroup a public API in argparse #144812
Copy link
Copy link
Open
Labels
pendingThe issue will be closed if no feedback is providedThe issue will be closed if no feedback is providedstdlibStandard Library Python modules in the Lib/ directoryStandard Library Python modules in the Lib/ directorytopic-typingtype-featureA feature request or enhancementA feature request or enhancement
Metadata
Metadata
Assignees
Labels
pendingThe issue will be closed if no feedback is providedThe issue will be closed if no feedback is providedstdlibStandard Library Python modules in the Lib/ directoryStandard Library Python modules in the Lib/ directorytopic-typingtype-featureA feature request or enhancementA feature request or enhancement
Fields
Give feedbackNo fields configured for issues without a type.
Projects
Status
No status
argparse.ArgumentParser.add_mutually_exclusive_group()returns anargparse._MutuallyExclusiveGroupinstance, 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:
is flagged as a type error because
_MutuallyExclusiveGroupis notArgumentParser, 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_subparserspublic.Proposal
Make
_MutuallyExclusiveGroup(and possibly_ArgumentGroup) public by removing the underscore prefix, or at minimum export a public type alias.Linked PRs