From 5c5fa343d8f00398852e426332f1946faed4b2c5 Mon Sep 17 00:00:00 2001 From: Justin Kunimune Date: Sat, 25 May 2024 23:06:21 -0400 Subject: [PATCH 1/2] 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. --- Doc/library/argparse.rst | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/Doc/library/argparse.rst b/Doc/library/argparse.rst index 0367c83d9369d3..85c76e6d33e753 100644 --- a/Doc/library/argparse.rst +++ b/Doc/library/argparse.rst @@ -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``:: From ea535e3c61d33fc33cfcf7da7bd3e7ddb26efc3c Mon Sep 17 00:00:00 2001 From: Justin Kunimune Date: Tue, 1 Oct 2024 13:48:06 -0400 Subject: [PATCH 2/2] Update Doc/library/argparse.rst Co-authored-by: Savannah Ostrowski --- Doc/library/argparse.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Doc/library/argparse.rst b/Doc/library/argparse.rst index 85c76e6d33e753..220b153dd70e44 100644 --- a/Doc/library/argparse.rst +++ b/Doc/library/argparse.rst @@ -722,7 +722,7 @@ exit_on_error ^^^^^^^^^^^^^ Normally, when you pass an invalid argument list to the :meth:`~ArgumentParser.parse_args` -method of an :class:`ArgumentParser`, it will print error info and exit with a status +method of an :class:`ArgumentParser`, it will print a *message* to :data:`sys.stderr` and exit with a status code of 2. If the user would like to catch errors manually, the feature can be enabled by setting