From af0d357138a38232817994ed0c932d9ff66eb8f9 Mon Sep 17 00:00:00 2001 From: Savannah Ostrowski Date: Tue, 10 Sep 2024 20:39:26 -0700 Subject: [PATCH 1/6] add mention of stderr for clarity to exit() --- 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 aa1341c8d4d4a8..f9119116dc22c8 100644 --- a/Doc/library/argparse.rst +++ b/Doc/library/argparse.rst @@ -2235,7 +2235,7 @@ Exiting methods .. method:: ArgumentParser.exit(status=0, message=None) This method terminates the program, exiting with the specified *status* - and, if given, it prints a *message* before that. The user can override + and, if given, it prints a *message* to stderr before that. The user can override this method to handle these steps differently:: class ErrorCatchingArgumentParser(argparse.ArgumentParser): From 48267926f05e7de8343849b4de1e389cacb07b34 Mon Sep 17 00:00:00 2001 From: Savannah Ostrowski Date: Tue, 10 Sep 2024 20:42:37 -0700 Subject: [PATCH 2/6] update error() for better grammar and consistency --- Doc/library/argparse.rst | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Doc/library/argparse.rst b/Doc/library/argparse.rst index f9119116dc22c8..051f8edc69ed7e 100644 --- a/Doc/library/argparse.rst +++ b/Doc/library/argparse.rst @@ -2246,8 +2246,8 @@ Exiting methods .. method:: ArgumentParser.error(message) - This method prints a usage message including the *message* to the - standard error and terminates the program with a status code of 2. + This method prints a usage message including the *message* to stderr + and terminates the program with a status code of 2. Intermixed parsing From 040e1a224337b76099c44830179ba18888ff0353 Mon Sep 17 00:00:00 2001 From: Savannah Ostrowski Date: Tue, 10 Sep 2024 20:43:33 -0700 Subject: [PATCH 3/6] grammar update --- 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 051f8edc69ed7e..5d6be4666ac488 100644 --- a/Doc/library/argparse.rst +++ b/Doc/library/argparse.rst @@ -2246,7 +2246,7 @@ Exiting methods .. method:: ArgumentParser.error(message) - This method prints a usage message including the *message* to stderr + This method prints a usage message, including the *message*, to stderr and terminates the program with a status code of 2. From 90000f27c6a48162131a60178b68cd1f7200029b Mon Sep 17 00:00:00 2001 From: Savannah Ostrowski Date: Thu, 19 Sep 2024 13:54:49 -0700 Subject: [PATCH 4/6] add docstring to exit as well --- Lib/argparse.py | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/Lib/argparse.py b/Lib/argparse.py index 100ef9f55cd2f7..9924c8b09300c3 100644 --- a/Lib/argparse.py +++ b/Lib/argparse.py @@ -2620,6 +2620,10 @@ def _print_message(self, message, file=None): # Exiting methods # =============== def exit(self, status=0, message=None): + """exit(status=0, message=None) + + Exit the program, optionally printing an exit message. + """ if message: self._print_message(message, _sys.stderr) _sys.exit(status) From 2c8112cfe60b762d0bae5df5f185f088e411d880 Mon Sep 17 00:00:00 2001 From: Savannah Ostrowski Date: Sun, 22 Sep 2024 14:07:04 -0700 Subject: [PATCH 5/6] Address PR comments --- Doc/library/argparse.rst | 10 +++++----- Lib/argparse.py | 4 ---- 2 files changed, 5 insertions(+), 9 deletions(-) diff --git a/Doc/library/argparse.rst b/Doc/library/argparse.rst index 5d6be4666ac488..8f59995f1bab90 100644 --- a/Doc/library/argparse.rst +++ b/Doc/library/argparse.rst @@ -1455,7 +1455,7 @@ The ``deprecated`` keyword argument of specifies if the argument is deprecated and will be removed in the future. For arguments, if ``deprecated`` is ``True``, then a warning will be -printed to standard error when the argument is used:: +printed to :data:`sys.stdout` when the argument is used:: >>> import argparse >>> parser = argparse.ArgumentParser(prog='snake.py') @@ -2235,8 +2235,8 @@ Exiting methods .. method:: ArgumentParser.exit(status=0, message=None) This method terminates the program, exiting with the specified *status* - and, if given, it prints a *message* to stderr before that. The user can override - this method to handle these steps differently:: + and, if given, it prints a *message* to :data:`sys.stdout` before that. + The user can override this method to handle these steps differently:: class ErrorCatchingArgumentParser(argparse.ArgumentParser): def exit(self, status=0, message=None): @@ -2246,8 +2246,8 @@ Exiting methods .. method:: ArgumentParser.error(message) - This method prints a usage message, including the *message*, to stderr - and terminates the program with a status code of 2. + This method prints a usage message, including the *message*, to + :data:`sys.stdout` and terminates the program with a status code of 2. Intermixed parsing diff --git a/Lib/argparse.py b/Lib/argparse.py index 485e55309ce04b..7988c447d03584 100644 --- a/Lib/argparse.py +++ b/Lib/argparse.py @@ -2618,10 +2618,6 @@ def _print_message(self, message, file=None): # Exiting methods # =============== def exit(self, status=0, message=None): - """exit(status=0, message=None) - - Exit the program, optionally printing an exit message. - """ if message: self._print_message(message, _sys.stderr) _sys.exit(status) From 3e4cf5cf7854d7e43d9ccbab819cd0d2e3233eab Mon Sep 17 00:00:00 2001 From: Savannah Ostrowski Date: Sun, 22 Sep 2024 14:29:41 -0700 Subject: [PATCH 6/6] update to stderr --- Doc/library/argparse.rst | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/Doc/library/argparse.rst b/Doc/library/argparse.rst index 8f59995f1bab90..c4e2dbcac2156c 100644 --- a/Doc/library/argparse.rst +++ b/Doc/library/argparse.rst @@ -1455,7 +1455,7 @@ The ``deprecated`` keyword argument of specifies if the argument is deprecated and will be removed in the future. For arguments, if ``deprecated`` is ``True``, then a warning will be -printed to :data:`sys.stdout` when the argument is used:: +printed to :data:`sys.stderr` when the argument is used:: >>> import argparse >>> parser = argparse.ArgumentParser(prog='snake.py') @@ -2235,7 +2235,7 @@ Exiting methods .. method:: ArgumentParser.exit(status=0, message=None) This method terminates the program, exiting with the specified *status* - and, if given, it prints a *message* to :data:`sys.stdout` before that. + and, if given, it prints a *message* to :data:`sys.stderr` before that. The user can override this method to handle these steps differently:: class ErrorCatchingArgumentParser(argparse.ArgumentParser): @@ -2247,7 +2247,7 @@ Exiting methods .. method:: ArgumentParser.error(message) This method prints a usage message, including the *message*, to - :data:`sys.stdout` and terminates the program with a status code of 2. + :data:`sys.stderr` and terminates the program with a status code of 2. Intermixed parsing