[Python-Dev] Python 2.7b1 and argparse's version action

Tobias Herp Tobias.Herp at gmx.de
Sun Apr 18 15:51:00 CEST 2010


Ben Finney schrieb:
> Nick Coghlan <ncoghlan at gmail.com> writes:
> 
>> I would be a lot happier if argparse as a standard library module just
>> followed optparse's lead here (i.e. defined '--version' only and punted
>> on the shorthand form).
>>
>> To deal with this in a backwards compatible way while remaining on the
>> path to more conventional behaviour, I suggest the following:
>>
>> 1. For Python 2.7, deprecate *just* the "-v" default behaviour for the
>> version. This means "--version" and "-v" will be set to invoke different
>> actions when the version argument is supplied (the latter will trigger a
>> deprecation warning if supplied, while the former will work normally).
>>
>> 2. For Python 3.2, don't create the "-v" shorthand at all (i.e. only
>> create "--version").
> 
> +1
> 
> As someone who uses the existing ‘optparse’ behaviour to implement a
> number of Unix command-line programs, the above all makes more sense for
> ‘argparse’ in the standard library if we're expecting it to be a smooth
> upgrade.

Guys, thanks for your feedback.

Let me see; the suggestion involves the '-v' being set in Python 2.7 by
default, but to another action, which yields a DeprecationWarning /and/
performs the version action, right?

The drawback would be: The '-v' wouldn't be available for other uses.
But I use it all the time (for verbosity).

I don't see why we shouldn't drop the '-v' altogether; where Python
standard libraries are concerned, argparse is a new module, and no
compatibility can be broken; people will expect this to follow the
optparse habits.

Programs developed against former versions of argparse will continue to
work, too; there will just not be a (non-standard) short option
generated, but the long option '--version' will be still there.
Honestly, how frequently do you query program versions?

Unfortunately adding a new '-V' default action /could/ break existing
programs, since people might have worked around the former default; thus
we couldn't do this.

Let's get rid of the default '-v' /now/.  This is clean, this is easy,
it won't break anything (with the possible exception of "prog -v"
version output parsers who deserve no better), and we would be done with it.

-- 
Tobias


More information about the Python-Dev mailing list