Python 2.7b1 and argparse's version action

Tobias Herp bruno-der-fragwuerdige at arcor.de
Sat Apr 17 21:53:15 EDT 2010


Hi, all,

I notice that Python 2.7 beta 1 now contains the argparse module, which
might be a good thing.  The code has been cleaned up, too.

But there is still one issue with argparse:
Completely unnecessarily, the 'version' constructor argument is now
deprecated.  This fact doesn't solve any problem I can think of; the
only effect is to make programming more cumbersome, and it is /one more/
difference to optparse.

The 'version' argument is a perfectly reasonable way to provide a script
with a simple version information feature.  Of course, it should only
define the '--version' argument; it *must not* define '-v' for this
purpose, since this is commonly used for verbosity.  I have lots of
scripts which use optparse, and every single one uses the version
argument.  I consider this a matter of good style.

Of course, if a more fancy version information is needed, it is
perfectly possible to just omit the version argument during creation
and build a special 'version' action, e.g. reporting the versions of all
imported modules.  No deprecation warnings are needed for this.

*Before Python 2.7 getting a production release*, IMNSHO the following
changes should be applied to argparse.py:

- removal of the deprecation warnings
- removal of the default usage of '-v'
  with the version information facility

This is a very simple thing to do; I'd happily provide a patch.

Just for the records, this is what optparse does:
- it defines -h and --help for the help (unless suppressed)
- it defines --version for the version (if version argument given)
This is how it should be.
This is how the vast majority of *x tools looks like.
  (well, some use '-h' for something like "host" or "human readable";
  but just a few strange misfits use -v instead of -V for the version.)
No reason to change this behaviour.

What do you think?

-- 
Cheers,

Tobias



More information about the Python-list mailing list