[Python-Dev] PEP 389: argparse - new command line parsing module (original) (raw)
André Malo nd at perlig.de
Sat Oct 3 20:35:04 CEST 2009
- Previous message: [Python-Dev] PEP 389: argparse - new command line parsing module
- Next message: [Python-Dev] PEP 389: argparse - new command line parsing module
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
- Steven D'Aprano wrote:
You don't need a comment warning that you are catching SystemExit because parseargs raises SystemExit, any more than you need a comment saying that you are catching ValueError because some function raises ValueError. The fact that you are catching an exception implies that the function might raise that exception. A comment like:
"Catching SystemExit because parseargs() throws SystemExit on parser errors." is up them with comments like this: x += 1 # Add 1 to x.
It's semantically different. You usually don't catch SystemExit directly, because you want your programs to be stopped. Additionally, a library exiting your program is badly designed, as it's unexpected. Thatswhy such a comment is useful.
Here's what I'd do: I'd subclass SystemExit in this case and raise the subclass from argparse. That way all parties here should be satisifed. (I do the same all the time in my signal handlers - that's another reason I'd rather not catch SystemExit directly as well :-)
nd
"Umfassendes Werk (auch fuer Umsteiger vom Apache 1.3)" -- aus einer Rezension
<http://pub.perlig.de/books.html#apache2>
- Previous message: [Python-Dev] PEP 389: argparse - new command line parsing module
- Next message: [Python-Dev] PEP 389: argparse - new command line parsing module
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]