Skip to content

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

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 11 commits into from
Sep 12, 2019
9 changes: 8 additions & 1 deletion Doc/library/argparse.rst
Original file line number Diff line number Diff line change
Expand Up @@ -2002,7 +2002,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)

Expand Down