Why is the argparse module so inflexible?

MRAB python at mrabarnett.plus.com
Sat Jun 29 11:58:42 EDT 2013


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
>>> 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.
>
[snip]
+1

It's the job of argparse to parse the arguments. What should happen if
they're invalid is for its caller to decide.




More information about the Python-list mailing list