8000 Note argparse exit code in documentation by jkunimune · Pull Request #119568 · python/cpython · GitHub
[go: up one dir, main page]

Skip to content

Note argparse exit code in documentation #119568

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 our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Oct 10, 2024
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
Note argparse exit code in documentation
It is currently stated that calling `ArgumentParser.error()` exits with a code of 2.  However, it is not explicitly stated that this method is used in `ArgumentParser.parse_args()` when the arguments are invalid.  Adding a note about the exit code to the `exit_on_error` argument of the `ArgumentParser` constructor makes this relationship explicit, and also makes this piece of information easier to notice.
  • Loading branch information
jkunimune authored May 26, 2024
commit 5c5fa343d8f00398852e426332f1946faed4b2c5
3 changes: 2 additions & 1 deletion Doc/library/argparse.rst
Original file line number Diff line number Diff line change
Expand Up @@ -722,7 +722,8 @@ exit_on_error
^^^^^^^^^^^^^

Normally, when you pass an invalid argument list to the :meth:`~ArgumentParser.parse_args`
method of an :class:`ArgumentParser`, it will exit with error info.
method of an :class:`ArgumentParser`, it will print error info and exit with a status
code of 2.

If the user would like to catch errors manually, the feature can be enabled by setting
``exit_on_error`` to ``False``::
Expand Down
0