Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #49416
| Path | csiph.com!usenet.pasdenom.info!weretis.net!feeder1.news.weretis.net!feeder.erje.net!eu.feeder.erje.net!xlned.com!feeder5.xlned.com!news2.euro.net!newsgate.cistron.nl!newsgate.news.xs4all.nl!post.news.xs4all.nl!not-for-mail |
|---|---|
| Return-Path | <mszamot@gmail.com> |
| X-Original-To | python-list@python.org |
| Delivered-To | python-list@mail.python.org |
| X-Spam-Status | OK 0.000 |
| X-Spam-Evidence | '*H*': 1.00; '*S*': 0.00; 'scripts': 0.03; 'explicitly': 0.05; 'debug': 0.07; 'debugging': 0.07; 'explicit': 0.07; 'parser': 0.07; 'sys': 0.07; 'default.': 0.09; 'hiding': 0.09; 'option,': 0.09; 'optparse': 0.09; 'runtime': 0.09; 'subject:Why': 0.09; 'subject:module': 0.09; 'suppress': 0.09; 'python': 0.11; 'def': 0.12; 'mostly': 0.14; 'belongs': 0.16; 'block.': 0.16; 'command-line': 0.16; 'decision,': 0.16; 'make,': 0.16; 'ought': 0.16; 'really?': 0.16; 'scripts.': 0.16; 'subclass': 0.16; 'subject:argparse': 0.16; 'exception': 0.16; 'fix': 0.17; 'wrote:': 0.18; 'library': 0.18; 'app': 0.19; '(but': 0.19; 'developer,': 0.19; 'code,': 0.22; 'import': 0.22; 'header :User-Agent:1': 0.23; 'error': 0.23; 'config': 0.24; "shouldn't": 0.24; '(or': 0.24; 'least': 0.26; 'header:In-Reply-To:1': 0.27; '[1]': 0.29; 'generally': 0.29; 'raise': 0.29; 'ease': 0.30; "i'm": 0.30; 'url:mailman': 0.30; 'easier': 0.31; 'lines': 0.31; '-0700,': 0.31; 'catching': 0.31; "d'aprano": 0.31; 'disable': 0.31; 'exceptions': 0.31; 'extending': 0.31; 'libraries': 0.31; 'steven': 0.31; 'allows': 0.31; 'class': 0.32; 'option': 0.32; 'url:python': 0.33; 'framework': 0.33; 'fri,': 0.33; 'subject:the': 0.34; 'could': 0.34; 'message.': 0.35; 'something': 0.35; 'but': 0.35; 'received:google.com': 0.35; 'there': 0.35; 'library.': 0.36; 'sat': 0.36; 'url:listinfo': 0.36; 'useful': 0.36; 'charset:us-ascii': 0.36; 'subject:?': 0.36; 'url:org': 0.36; 'should': 0.36; 'experience,': 0.37; 'application': 0.37; 'so,': 0.37; 'sometimes': 0.38; 'to:addr:python-list': 0.38; 'pm,': 0.38; 'rather': 0.38; 'that,': 0.38; 'anything': 0.39; 'to:addr:python.org': 0.39; 'either': 0.39; 'called': 0.40; 'url:mail': 0.40; 'easy': 0.60; 'catch': 0.60; 'information,': 0.61; 'first': 0.61; 'content-disposition:inline': 0.62; 'skip:n 10': 0.64; 'places': 0.64; 'more': 0.64; 'default': 0.69; 'skip:a 40': 0.72; 'potentially': 0.81; 'console,': 0.84; 'ethan': 0.84; 'furman': 0.84; 'maybe,': 0.84; 'zen': 0.84; 'average': 0.93; '2013': 0.98 |
| DKIM-Signature | v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=date:from:to:subject:message-id:references:mime-version :content-type:content-disposition:in-reply-to:user-agent; bh=c9tLaSNU68arxszU2lraXILZjqNOdhKiNu9L+ULiSN4=; b=Qc+4zwVsy+XqeZmTuJl2myFXNC9DgjkPiXSyYllCQm0/0LvIfSe5Oi36y0IeqJ3mpV xcVZLsCn63xI3vnKVMYTMB+3NCHWAVkagtsNxOrQkeOMQO5DrtRYgXg9YiACGGR2cOaU 31wktzayGuE/kXJ5bEYpPFS6jGXMNXGKQ58C/OlUSj53uePRQ3REyKLdNmE4IoTXJwBB 8FyK/ZvIi2HC0FPKfcUf9V1M4CHhnB7e7k+d58R/sdMWl7Etz8v3q4dDfdMWjZxrvxU9 dJ4W67K84h0YQzMoRSWIf+vuAcE2uJkf9Gw0e3OCKk9gCrrBVexq2uRWgNtO7GYS58ii hDsw== |
| X-Received | by 10.194.157.99 with SMTP id wl3mr13759721wjb.76.1372509499749; Sat, 29 Jun 2013 05:38:19 -0700 (PDT) |
| Date | Sat, 29 Jun 2013 13:38:00 +0100 |
| From | Marcin Szamotulski <mszamot@gmail.com> |
| To | python-list@python.org |
| Subject | Re: Why is the argparse module so inflexible? |
| References | <mailman.3924.1372337705.3114.python-list@python.org> <roy-57E318.09080527062013@70-1-84-166.pools.spcsdns.net> <51CC42E3.3070508@gmail.com> <mailman.3933.1372348963.3114.python-list@python.org> <51ccc190$0$29999$c3e8da3$5496439d@news.astraweb.com> <mailman.3974.1372469806.3114.python-list@python.org> <51ce708f$0$29999$c3e8da3$5496439d@news.astraweb.com> |
| MIME-Version | 1.0 |
| Content-Type | text/plain; charset=us-ascii |
| Content-Disposition | inline |
| In-Reply-To | <51ce708f$0$29999$c3e8da3$5496439d@news.astraweb.com> |
| User-Agent | Mutt/1.5.21 (2010-09-15) |
| X-BeenThere | python-list@python.org |
| X-Mailman-Version | 2.1.15 |
| Precedence | list |
| List-Id | General discussion list for the Python programming language <python-list.python.org> |
| List-Unsubscribe | <http://mail.python.org/mailman/options/python-list>, <mailto:python-list-request@python.org?subject=unsubscribe> |
| List-Archive | <http://mail.python.org/pipermail/python-list/> |
| List-Post | <mailto:python-list@python.org> |
| List-Help | <mailto:python-list-request@python.org?subject=help> |
| List-Subscribe | <http://mail.python.org/mailman/listinfo/python-list>, <mailto:python-list-request@python.org?subject=subscribe> |
| Newsgroups | comp.lang.python |
| Message-ID | <mailman.3986.1372509508.3114.python-list@python.org> (permalink) |
| Lines | 69 |
| NNTP-Posting-Host | 2001:888:2000:d::a6 |
| X-Trace | 1372509508 news.xs4all.nl 16006 [2001:888:2000:d::a6]:57390 |
| X-Complaints-To | abuse@xs4all.nl |
| Xref | csiph.com comp.lang.python:49416 |
Show key headers only | View raw
On 05:28 Sat 29 Jun , Steven D'Aprano wrote:
> On Fri, 28 Jun 2013 18:36:37 -0700, Ethan Furman wrote:
>
> > On 06/27/2013 03:49 PM, Steven D'Aprano wrote:
> >>
> >> [rant]
> >> I think it is lousy design for a framework like argparse to raise a
> >> custom ArgumentError in one part of the code, only to catch it
> >> elsewhere and call sys.exit. At the very least, that OUGHT TO BE A
> >> CONFIG OPTION, and OFF BY DEFAULT.
>
> [emphasis added]
>
> >> Libraries should not call sys.exit, or raise SystemExit. Whether to
> >> quit or not is not the library's decision to make, that decision
> >> belongs to the application layer. Yes, the application could always
> >> catch SystemExit, but it shouldn't have to.
> >
> > So a library that is explicitly designed to make command-line scripts
> > easier and friendlier should quit with a traceback?
> >
> > Really?
>
> Yes, really.
>
> Tracebacks are not that unfriendly, generally speaking. In my experience,
> the average non-technical person is no more confused and distressed by a
> traceback extending over thirty lines than they are by a one line error
> message. As the developer, I should see the tracebacks by default[1]. If
> I want to suppress or simplify them, then I should take explicit steps to
> do so, either by catching the exception and calling sys.exit myself, or
> at least by setting a runtime config option to the library.
>
> This also allows me to enable debugging in my app by showing tracebacks,
> or disable it by hiding them. That should be my decision, not the
> library. If the library catches exceptions then exits, throwing away
> potentially useful information, that makes it difficult to debug anything
> relying on the library.
>
> I'm willing to concede that, just maybe, something like argparse could
> default to "catch exceptions and exit" ON rather than OFF.
>
>
> [1] There's something in the Zen of Python about that...
>
>
> --
> Steven
> --
>
Although I got confused at the first time I was using argparse (or
optparse which is now obsolte and also has this feature), I see the
value when you write scripts. It is mostly annoying when playing with
it in a console, but there is a very easy (but partial) fix for that:
just subclass argparse.ArgumentParser:
import sys
class ArgumentParser(argparse.ArgumentParser):
def exit(self, status=0, message=None):
if message:
self._print_message(message, sys.stderr)
now the parser will not exit, though there is no ease fix to get the
traceback: self.exit() is called in various places sometimes inside
a try block.
Best regards,
Marcin http://mail.python.org/mailman/listinfo/python-list
Back to comp.lang.python | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
Why is the argparse module so inflexible? Andrew Berg <robotsondrugs@gmail.com> - 2013-06-27 07:54 -0500
Re: Why is the argparse module so inflexible? Roy Smith <roy@panix.com> - 2013-06-27 09:08 -0400
Re: Why is the argparse module so inflexible? Andrew Berg <robotsondrugs@gmail.com> - 2013-06-27 08:49 -0500
Re: Why is the argparse module so inflexible? Dave Angel <davea@davea.name> - 2013-06-27 12:02 -0400
Re: Why is the argparse module so inflexible? Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2013-06-27 22:49 +0000
Re: Why is the argparse module so inflexible? Cameron Simpson <cs@zip.com.au> - 2013-06-28 09:34 +1000
Re: Why is the argparse module so inflexible? Ethan Furman <ethan@stoneleaf.us> - 2013-06-28 18:36 -0700
Re: Why is the argparse module so inflexible? rusi <rustompmody@gmail.com> - 2013-06-28 21:12 -0700
Re: Why is the argparse module so inflexible? Terry Reedy <tjreedy@udel.edu> - 2013-06-29 00:37 -0400
Re: Why is the argparse module so inflexible? Roy Smith <roy@panix.com> - 2013-06-29 10:12 -0400
Re: Why is the argparse module so inflexible? Andrew Berg <robotsondrugs@gmail.com> - 2013-06-29 09:17 -0500
Re: Why is the argparse module so inflexible? Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2013-06-29 05:28 +0000
Re: Why is the argparse module so inflexible? Marcin Szamotulski <mszamot@gmail.com> - 2013-06-29 13:38 +0100
Re: Why is the argparse module so inflexible? MRAB <python@mrabarnett.plus.com> - 2013-06-29 16:58 +0100
Re: Why is the argparse module so inflexible? Ethan Furman <ethan@stoneleaf.us> - 2013-06-29 12:17 -0700
Re: Why is the argparse module so inflexible? Modulok <modulok@gmail.com> - 2013-06-28 19:39 -0600
Re: Why is the argparse module so inflexible? Isaac To <isaac.to@gmail.com> - 2013-06-29 12:37 +0800
Re: Why is the argparse module so inflexible? Robert Kern <robert.kern@gmail.com> - 2013-06-27 20:47 +0100
csiph-web