Uh oh!
There was an error while loading.Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork34k
gh-69223: Document that add_argument returns an Action object#144452
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to ourterms of service andprivacy statement. We’ll occasionally send you account related emails.
Already on GitHub?Sign in to your account
base:main
Are you sure you want to change the base?
Conversation
Add documentation noting that ArgumentParser.add_argument() returnsan Action object, which can be used for further customization orinspection of argument properties.Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
| * deprecated_ - Whether or not use of the argument is deprecated. | ||
| The method returns an :class:`Action` object representing the argument. | ||
| This object can be used to further customize behavior or to inspect |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others.Learn more.
It cannot be used for customize the behavior. Action objects are immutable afterwards.
A Python core developer has requested some changes be made to your pull request before we can consider merging it. If you could please address their requests along with any other requests in other reviews from core developers that would be appreciated. Once you have made the requested changes, please leave a comment on this pull request containing the phrase |
kovan commentedFeb 3, 2026
I tested this and Action objects are actually mutable, and modifications after importargparse# Modify help after addingparser=argparse.ArgumentParser()action=parser.add_argument('--foo',help='Original help')action.help='Modified help'parser.print_help()# Shows: --foo FOO Modified help# Modify default after addingparser2=argparse.ArgumentParser()action2=parser2.add_argument('--bar',default=10)action2.default=99args=parser2.parse_args([])print(args.bar)# Output: 99# Modify choices after addingparser3=argparse.ArgumentParser()action3=parser3.add_argument('--choice',choices=['a','b'])action3.choices= ['a','b','c']args3=parser3.parse_args(['--choice','c'])# Works!# Modify required after addingparser4=argparse.ArgumentParser()action4=parser4.add_argument('--opt')action4.required=Trueparser4.parse_args([])# Raises error: --opt is required All modifications ( |
kovan commentedFeb 3, 2026
I have made the requested changes; please review again |
Thanks for making the requested changes! @picnixz: please review the changes made to this pull request. |
picnixz commentedFeb 3, 2026 • edited
Loading Uh oh!
There was an error while loading.Please reload this page.
edited
Uh oh!
There was an error while loading.Please reload this page.
The question isn't whether it's possible to do it or not, but whether it's meant to be part of the public API or not. Argparse has lots of "public-looking interfaces" but not everything is meant to be public. The attributes may not even be themselves part of the public API (despite them not having underscores). So we should first decide whether Action is public and which part of Action is public. |
Uh oh!
There was an error while loading.Please reload this page.
Summary
ArgumentParser.add_argument()returns anActionobjectTest plan
make checkpassed🤖 Generated withClaude Code
📚 Documentation preview 📚:https://cpython-previews--144452.org.readthedocs.build/