This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Title: sys.exit() called from optparse - bad, bad, bad
Type: Stage:
Components: Versions:
Status: closed Resolution:
Dependencies: Superseder: sys.exit() called from optparse - bad, bad, bad
View: 3079
Assigned To: Nosy List: skip.montanaro
Priority: normal Keywords:

Created on 2008-06-11 22:50 by skip.montanaro, last changed 2022-04-11 14:56 by admin. This issue is now closed.

Messages (2)
msg68030 - (view) Author: Skip Montanaro (skip.montanaro) * (Python triager) Date: 2008-06-11 22:50
This seems like a bug in optparse.OptionParser:

    def exit(self, status=0, msg=None):
        if msg:

    def error(self, msg):
        """error(msg : string)

        Print a usage message incorporating 'msg' to stderr and exit.
        If you override this in a subclass, it should not return -- it
        should either exit or raise an exception.
        self.exit(2, "%s: error: %s\n" % (self.get_prog_name(), msg))

By default I think it should raise an exception when it encounters an error,
not exit.  Programmers shouldn't be forced to subclass code in the standard
library to get recommended practice.

If you feel this behavior can't be changed in 2.6 it should at least be
corrected in 3.0.

msg68037 - (view) Author: Skip Montanaro (skip.montanaro) * (Python triager) Date: 2008-06-11 23:46
I originally sent this by email but never saw it pop up.  I eventually 
submitted via the web.
Date User Action Args
2022-04-11 14:56:35adminsetgithub: 47334
2008-06-11 23:47:08skip.montanarosetstatus: open -> closed
2008-06-11 23:46:47skip.montanarosetsuperseder: sys.exit() called from optparse - bad, bad, bad
messages: + msg68037
2008-06-11 22:50:18skip.montanarocreate