bpo-37908: Add an example of ArgumentParser.exit() (GH-15455)

Co-Authored-By: Brandt Bucher <brandtbucher@gmail.com>
(cherry picked from commit b1a2abdb06)

Co-authored-by: Hai Shi <shihai1992@gmail.com>
This commit is contained in:
Miss Islington (bot)
2019-09-12 08:43:14 -07:00
committed by GitHub
parent a0d4aac50b
commit 6dc3e61c51

View File

@@ -2001,7 +2001,14 @@ 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.
and, if given, it prints a *message* before that. The user can override
this method to handle these steps differently::
class ErrorCatchingArgumentParser(argparse.ArgumentParser):
def exit(self, status=0, message=None):
if status:
raise Exception(f'Exiting because of an error: {message}')
exit(status)
.. method:: ArgumentParser.error(message)