Peter V <peter.varhe...@gmail.com> added the comment:

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.

----------
nosy: +bigbird

_______________________________________
Python tracker <rep...@bugs.python.org>
<https://bugs.python.org/issue41255>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com

Reply via email to