Why is the argparse module so inflexible?

Terry Reedy tjreedy at udel.edu
Sat Jun 29 00:37:23 EDT 2013


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 elsewhere
>>> and call sys.exit. At the very least, that ought to be a config option,
>>> and off by default.
>>>
>>> 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?
>
> 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 
module into an app. With the responses I have seen here, I agree that 
this is a bit short-sighted, as inflexible behavior. The tracker issue 
could use more review and comment.

-- 
Terry Jan Reedy




More information about the Python-list mailing list