Skip to content

gh-85935: Check for nargs=0 for positional arguments in argparse#124839

Merged
serhiy-storchaka merged 4 commits into
python:mainfrom
serhiy-storchaka:argparse-nargs-0-positional
Oct 12, 2024
Merged

gh-85935: Check for nargs=0 for positional arguments in argparse#124839
serhiy-storchaka merged 4 commits into
python:mainfrom
serhiy-storchaka:argparse-nargs-0-positional

Conversation

@serhiy-storchaka

@serhiy-storchaka serhiy-storchaka commented Oct 1, 2024

Copy link
Copy Markdown
Member

Raise ValueError in add_argument() if either explicit nargs=0 or action that does not consume arguments (like 'store_const' or 'store_true') is specified for positional argument.

Raise ValueError in add_argument() if either explicit nargs=0 or action
that does not consume arguments (like 'store_const' or 'store_true') is
specified for positional argument.

@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.

Overall, LGTM. I had one comment about whether we could be more actionable in the error message, but there may be existing style guidance around error messages that I don't know about, which makes my comment moot.

Comment thread Lib/argparse.py
Comment thread Misc/NEWS.d/next/Library/2024-10-01-13-11-53.gh-issue-85935.CTwJUy.rst Outdated
…wJUy.rst

Co-authored-by: Savannah Ostrowski <savannahostrowski@gmail.com>

@serhiy-storchaka serhiy-storchaka left a comment

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Thank you for your review @savannahostrowski. I think that the error messages are in line with existing error messages and do not need to be too verbose. This is a task for documentation.

Comment thread Lib/argparse.py
@serhiy-storchaka serhiy-storchaka merged commit 9944ad3 into python:main Oct 12, 2024
@serhiy-storchaka serhiy-storchaka deleted the argparse-nargs-0-positional branch October 12, 2024 13:04
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants