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.

classification
Title: sys.exit() called from optparse - bad, bad, bad
Type: Stage:
Components: Versions:
process
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:
            sys.stderr.write(msg)
        sys.exit(status)

    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.print_usage(sys.stderr)
        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.

Skip
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.
History
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