Re: Why is the argparse module so inflexible?

2013-06-29 Thread Marcin Szamotulski
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

Re: Why is the argparse module so inflexible?

2013-06-29 Thread Roy Smith
In article mailman.3980.1372480662.3114.python-l...@python.org, Terry Reedy tjre...@udel.edu wrote: So a library that behaves like an app is OK? No, Steven is right as a general rule (do not raise SystemExit), but argparse was considered an exception because its purpose is to turn a

Re: Why is the argparse module so inflexible?

2013-06-29 Thread Andrew Berg
On 2013.06.29 09:12, Roy Smith wrote: What is the tracker issue number or url? http://bugs.python.org/issue9938 -- CPython 3.3.2 | Windows NT 6.2.9200 / FreeBSD 9.1 -- http://mail.python.org/mailman/listinfo/python-list

Re: Why is the argparse module so inflexible?

2013-06-29 Thread MRAB
On 29/06/2013 06:28, 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

Re: Why is the argparse module so inflexible?

2013-06-29 Thread Ethan Furman
On 06/28/2013 10:28 PM, Steven D'Aprano wrote: I'm willing to concede that, just maybe, something like argparse could default to catch exceptions and exit ON rather than OFF. On this we can agree. :) -- ~Ethan~ -- http://mail.python.org/mailman/listinfo/python-list

Re: Why is the argparse module so inflexible?

2013-06-28 Thread Andrew Berg
After getting over the hurdles I initially explained and moving forward, I've found that standard command-line parsing and its conventions are far too ingrained in the design of argparse to make it useful as a general command parser. I think I would end up overriding a substantial amount of the

Re: Why is the argparse module so inflexible?

2013-06-28 Thread Ethan Furman
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.

Re: Why is the argparse module so inflexible?

2013-06-28 Thread Modulok
Have you looked into docopt? -Modulok- On Fri, Jun 28, 2013 at 7:36 PM, Ethan Furman et...@stoneleaf.us 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

Re: Why is the argparse module so inflexible?

2013-06-28 Thread rusi
On Saturday, June 29, 2013 7:06:37 AM UTC+5:30, 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

Re: Why is the argparse module so inflexible?

2013-06-28 Thread Isaac To
On Sat, Jun 29, 2013 at 9:36 AM, Ethan Furman et...@stoneleaf.us wrote: On 06/27/2013 03:49 PM, Steven D'Aprano wrote: 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,

Re: Why is the argparse module so inflexible?

2013-06-28 Thread Terry Reedy
On 6/29/2013 12:12 AM, rusi wrote: On Saturday, June 29, 2013 7:06:37 AM UTC+5:30, 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

Re: Why is the argparse module so inflexible?

2013-06-28 Thread Steven D'Aprano
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,

Why is the argparse module so inflexible?

2013-06-27 Thread Andrew Berg
I've begun writing a program with an interactive prompt, and it needs to parse input from the user. I thought the argparse module would be great for this, but unfortunately it insists on calling sys.exit() at any sign of trouble instead of letting its ArgumentError exception propagate so that I

Re: Why is the argparse module so inflexible?

2013-06-27 Thread Joshua Landau
On 27 June 2013 13:54, Andrew Berg robotsondr...@gmail.com wrote: I've begun writing a program with an interactive prompt, and it needs to parse input from the user. I thought the argparse module would be great for this, but unfortunately it insists on calling sys.exit() at any sign of

Re: Why is the argparse module so inflexible?

2013-06-27 Thread Roy Smith
In article mailman.3924.1372337705.3114.python-l...@python.org, Andrew Berg robotsondr...@gmail.com wrote: I've begun writing a program with an interactive prompt, and it needs to parse input from the user. I thought the argparse module would be great for this, but unfortunately it insists

Re: Why is the argparse module so inflexible?

2013-06-27 Thread Andrew Berg
On 2013.06.27 08:08, Roy Smith wrote: Can you give us a concrete example of what you're trying to do? The actual code I've written so far isn't easily condensed into a short simple snippet. I'm trying to use argparse to handle all the little details of parsing and verifying arguments in the

Re: Why is the argparse module so inflexible?

2013-06-27 Thread Dave Angel
On 06/27/2013 09:49 AM, Andrew Berg wrote: On 2013.06.27 08:08, Roy Smith wrote: Can you give us a concrete example of what you're trying to do? The actual code I've written so far isn't easily condensed into a short simple snippet. I'm trying to use argparse to handle all the little details

Re: Why is the argparse module so inflexible?

2013-06-27 Thread Terry Reedy
On 6/27/2013 8:54 AM, Andrew Berg wrote: I've begun writing a program with an interactive prompt, and it needs to parse input from the user. I thought the argparse module would be great for this, It is outside argparse's intended domain of application -- parsing command line arguments. The

Re: Why is the argparse module so inflexible?

2013-06-27 Thread Dave Angel
On 06/27/2013 02:05 PM, Terry Reedy wrote: On 6/27/2013 8:54 AM, Andrew Berg wrote: I've begun writing a program with an interactive prompt, and it needs to parse input from the user. I thought the argparse module would be great for this, It is outside argparse's intended domain of

Re: Why is the argparse module so inflexible?

2013-06-27 Thread Terry Reedy
On 6/27/2013 2:18 PM, Dave Angel wrote: On 06/27/2013 02:05 PM, Terry Reedy wrote: On 6/27/2013 8:54 AM, Andrew Berg wrote: I've begun writing a program with an interactive prompt, and it needs to parse input from the user. I thought the argparse module would be great for this, It is

Re: Why is the argparse module so inflexible?

2013-06-27 Thread Ethan Furman
On 06/27/2013 11:39 AM, Terry Reedy wrote: On 6/27/2013 2:18 PM, Dave Angel wrote: On 06/27/2013 02:05 PM, Terry Reedy wrote: On 6/27/2013 8:54 AM, Andrew Berg wrote: I've begun writing a program with an interactive prompt, and it needs to parse input from the user. I thought the argparse

Re: Why is the argparse module so inflexible?

2013-06-27 Thread Robert Kern
On 2013-06-27 17:02, Dave Angel wrote: On 06/27/2013 09:49 AM, Andrew Berg wrote: On 2013.06.27 08:08, Roy Smith wrote: Can you give us a concrete example of what you're trying to do? The actual code I've written so far isn't easily condensed into a short simple snippet. I'm trying to use

Re: Why is the argparse module so inflexible?

2013-06-27 Thread Jason Swails
On Thu, Jun 27, 2013 at 2:50 PM, Ethan Furman et...@stoneleaf.us wrote: If the OP is writing an interactive shell, shouldn't `cmd` be used instead of `argparse`? argparse is, after all, intended for argument parsing of command line scripts, not for interactive work. He _is_ using cmd.

Re: Why is the argparse module so inflexible?

2013-06-27 Thread Grant Edwards
On 2013-06-27, Jason Swails jason.swa...@gmail.com wrote: He _is_ using cmd. He's subclassed cmd.Cmd and trying to use argparse to handle argument parsing in the Cmd.precmd method to preprocess the user input. [...] Having subclassed cmd.Cmd myself in one of my programs and written my own

Re: Why is the argparse module so inflexible?

2013-06-27 Thread Chris Angelico
On Fri, Jun 28, 2013 at 8:19 AM, Grant Edwards invalid@invalid.invalid wrote: On 2013-06-27, Jason Swails jason.swa...@gmail.com wrote: He _is_ using cmd. He's subclassed cmd.Cmd and trying to use argparse to handle argument parsing in the Cmd.precmd method to preprocess the user input.

Re: Why is the argparse module so inflexible?

2013-06-27 Thread Steven D'Aprano
On Thu, 27 Jun 2013 12:02:22 -0400, Dave Angel wrote: On 06/27/2013 09:49 AM, Andrew Berg wrote: On 2013.06.27 08:08, Roy Smith wrote: Can you give us a concrete example of what you're trying to do? The actual code I've written so far isn't easily condensed into a short simple snippet. I'm

Re: Why is the argparse module so inflexible?

2013-06-27 Thread Cameron Simpson
On 27Jun2013 11:50, Ethan Furman et...@stoneleaf.us wrote: | If the OP is writing an interactive shell, shouldn't `cmd` be used | instead of `argparse`? argparse is, after all, intended for | argument parsing of command line scripts, not for interactive work. This is specious. I invoke command

Re: Why is the argparse module so inflexible?

2013-06-27 Thread Cameron Simpson
On 27Jun2013 22:49, Steven D'Aprano steve+comp.lang.pyt...@pearwood.info 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

Re: Why is the argparse module so inflexible?

2013-06-27 Thread Tim Chase
On 2013-06-28 09:02, Cameron Simpson wrote: On 27Jun2013 11:50, Ethan Furman et...@stoneleaf.us wrote: | If the OP is writing an interactive shell, shouldn't `cmd` be used | instead of `argparse`? argparse is, after all, intended for | argument parsing of command line scripts, not for

Re: Why is the argparse module so inflexible?

2013-06-27 Thread Oscar Benjamin
On 27 June 2013 22:30, Jason Swails jason.swa...@gmail.com wrote: An alternative is, of course, to simply subclass ArgumentParser and copy over all of the code that catches an ArgumentError to eliminate the internal exception handling and instead allow them to propagate the call stack. I

Re: Why is the argparse module so inflexible?

2013-06-27 Thread Jason Swails
On Thu, Jun 27, 2013 at 8:22 PM, Tim Chase python.l...@tim.thechases.comwrote: On 2013-06-28 09:02, Cameron Simpson wrote: On 27Jun2013 11:50, Ethan Furman et...@stoneleaf.us wrote: | If the OP is writing an interactive shell, shouldn't `cmd` be used | instead of `argparse`? argparse is,

Re: Why is the argparse module so inflexible?

2013-06-27 Thread Andrew Berg
I appreciate the responses from everyone. I knew I couldn't be the only who thought this behavior was unnecessarily limiting. I found a ticket on the bug tracker. A patch was even submitted, but obviously it didn't make it into 3.3. Hopefully, it will make it into 3.4 with some prodding.