Skip to content

gh-144812: Make argparse group classes public - #158045

Merged
savannahostrowski merged 4 commits into
python:mainfrom
gaborbernat:gh-144812-public-argparse-groups
Oct 21, 2026
Merged

savannahostrowski merged 4 commits into
python:mainfrom
gaborbernat:gh-144812-public-argparse-groups

Conversation

@gaborbernat

@gaborbernat gaborbernat commented Sep 23, 2026 •

Copy link
Copy Markdown
Contributor

Following @savannahostrowski's suggestion on the issue, this makes ArgumentGroup and MutuallyExclusiveGroup public and keeps _ArgumentGroup and _MutuallyExclusiveGroup as aliases, since existing code imports them.

The docs cover what they already promised: the objects that add_argument_group() and add_mutually_exclusive_group() return, and their add_argument() and add_mutually_exclusive_group() methods. The constructors stay implementation details.

This replaces the protocol approach from #150597.

Code that annotates the return values of add_argument_group() and
add_mutually_exclusive_group() has to import the private _ArgumentGroup and
_MutuallyExclusiveGroup today. Public names give that code a supported type,
and the old names stay as aliases so existing imports keep working.
@read-the-docs-community

read-the-docs-community Bot commented Sep 23, 2026 •

Copy link
Copy Markdown

@gaborbernat

Copy link
Copy Markdown
Contributor Author

@savannahostrowski would you be able to take a look here? Thank you. ❤️

@savannahostrowski

Copy link
Copy Markdown
Member

@gaborbernat Sorry for the delay, I'm hoping to take a look at this in the coming week! Thanks for the ping!

@savannahostrowski savannahostrowski left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just a small question about documentation clarity.

We’ll also need a corresponding typeshed update. Their policy is to accept changes for new Python versions after the first beta, so that can follow once 3.16.0b1 is out (we don't need to hold up this PR for it though, just wanted to mention it)

Comment thread Doc/library/argparse.rst Outdated
@bedevere-app bedevere-app Bot added the type-feature A feature request or enhancement label Oct 20, 2026
@savannahostrowski
savannahostrowski enabled auto-merge (squash) October 20, 2026 23:51
@savannahostrowski
savannahostrowski merged commit d5e28e1 into python:main Oct 21, 2026
53 checks passed
@gaborbernat
gaborbernat deleted the gh-144812-public-argparse-groups branch October 21, 2026 16:39
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

type-feature A feature request or enhancement

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants