* Steven D'Aprano wrote: > You don't need a comment warning that you are catching SystemExit > because parse_args 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 parse_args() 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> _______________________________________________ Python-Dev mailing list Python-Dev@python.org http://mail.python.org/mailman/listinfo/python-dev Unsubscribe: http://mail.python.org/mailman/options/python-dev/archive%40mail-archive.com