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.

Author bigbird
Recipients bigbird, mhughes, paul.j3, rhettinger, xtreak
Date 2021-06-22.14:59:21
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1624373961.84.0.139083984689.issue41255@roundup.psfhosted.org>
In-reply-to
Content
I'm new to Python bugtracker and I may misunderstand the discussion. But I think this is a real bug in argparse, not a documentation problem.

My usecase was that I wanted to add argparse to a GUI application where print and exit is a wrong option. So I set `argparse.ArgumentParser(exit_on_error=False)` but I failed with that, system exited whatever I tried. Exit in this case is not an option, I expected a dedicated exception after that. 

Digging a bit deeper I found that I can create a custom class and overwrite the `ArgumentParser.exit(status=0, message=None)` but still, as a simple user of the standard library why should I do that?

This would be a minimalist example how this can be solved in argparse code:

    def exit(self, status=0, message=None):
        if message:
            self._print_message(message, _sys.stderr)
        if self.exit_on_error:
            _sys.exit(status)
        else:
            raise ArgumentError(...)

But considering GUI or interactive usage this is still not enough, sys.stdout and sys.stderr is written, that do not exists in GUI case, so these parts also need some re-design.
History
Date User Action Args
2021-06-22 14:59:21bigbirdsetrecipients: + bigbird, rhettinger, paul.j3, xtreak, mhughes
2021-06-22 14:59:21bigbirdsetmessageid: <1624373961.84.0.139083984689.issue41255@roundup.psfhosted.org>
2021-06-22 14:59:21bigbirdlinkissue41255 messages
2021-06-22 14:59:21bigbirdcreate