Python 2.7b1 and argparse's version action
Hi, all, (I don't know whether the first attempt to post this went through; I could'nt find it, so I retry. My apologies for any inconvenience...) I noticed that Python 2.7 beta 1 now contains the argparse module, which might be a good thing. The code has been cleaned up, too, compared to the current version 1.1. But there is still one issue with argparse; to tell the story from the beginning: The ArgumentParser class uses uses '-v' as a default short option for the 'tell me the program version' facility. Since this is commonly used for verbosity, and the vast majority of *X commandline tools use '-V' instead (if they bother to accompany '--version' with a short option at all). Therefore I submitted an issue report at http://code.google.com/p/argparse/issues/detail?id=43. To put it short: *Argparse should simply do this like optparse does already.* I.e., use '--version', '--help' and '-h' by default, but not '-v'. Subsequently I spent a hard time arguing. (Perhaps it was somewhat distracting that I proposed a way of postponing the creation of the help and version options and to provide them with the short options which are left unused e.g. for hosts (database clients), human readability (ls, du, etc.) or verbosity; Steven had stated it might break backward compatibility if the '-v' option string for version output would be dropped which might be relied on by other programs which parse the output. IMO, however, anyone should be beaten who relies on '-v' giving the version while '--version' has been present all the time. The Zen of Python, 2nd aphorism: "Explicit is better than implicit") What happened was the following: 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, and '-V' is widely used to accompany '--version'. I have lots of scripts which use optparse, and every single one uses the version argument. I consider this a matter of good style. The deprecation of the 'version' argument press-gangs people to replace it by parser.add_argument('--version', action='version', version='<the version>', # the only common part help="show program's version number and exit") in every single script (which violates the DRY principle, by the way). Of course, if a more fancy version information is needed, e.g. reporting the versions of all imported modules, it is perfectly possible to just omit the version argument during creation and build a special 'version' action. No deprecation warnings are needed for this. *Before Python 2.7 reaches productivity stage*, 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. (The only complicated task might be to make the unit tests reflect the change; but for a start, 7 lines of the test_main function could be dropped.) 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 (regarding the version, at least). This is how the vast majority of *x tools looks like. No reason to change this behaviour. What do you think? -- Cheers, Tobias
Tobias Herp wrote:
*Before Python 2.7 reaches productivity stage*, 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. (The only complicated task might be to make the unit tests reflect the change; but for a start, 7 lines of the test_main function could be dropped.)
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 (regarding the version, at least). This is how the vast majority of *x tools looks like. No reason to change this behaviour.
What do you think?
I can see Steven's argument from an argparse point of view, but I think he is taking backwards compatibility to an unhealthy extreme. Deprecating a perfectly valid option *just* because someone might be relying on -v instead of -V as the shorthand for version? A phrase involving babies and bathwater comes to mind... 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"). Cheers, Nick. -- Nick Coghlan | ncoghlan@gmail.com | Brisbane, Australia ---------------------------------------------------------------
Nick Coghlan
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. -- \ “Natural catastrophes are rare, but they come often enough. We | `\ need not force the hand of nature.” —Carl Sagan, _Cosmos_, 1980 | _o__) | Ben Finney
Ben Finney schrieb:
Nick Coghlan
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
On Sun, Apr 18, 2010 at 4:03 AM, Nick Coghlan
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).
It's not clear how you would do this. If you can suggest a patch, I'd be happy to consider it. However, and the moment, you get "-v" and "--version" by simply specifying ArgumentParser(..., version="XXX"). So how do you deprecate just the "-v"? All I can imagine you mean is to issue a deprecation warning whenever a user of the script provides "-v" at the command line, but that seems sketchy to me - we'd be deprecating features of someone's *application*, not features of the argparse *library*. Steve -- Where did you get that preposterous hypothesis? Did Steve tell you that? --- The Hiphopopotamus
Steven Bethard schrieb:
On Sun, Apr 18, 2010 at 4:03 AM, Nick Coghlan
wrote: 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).
[...]
All I can imagine you mean is to issue a deprecation warning whenever a user of the script provides "-v" at the command line, but that seems sketchy to me - we'd be deprecating features of someone's *application*, not features of the argparse *library*.
It would raise warnings when the option is /used/ (rather than defined; such warnings address programmers, though), and it wouldn't free '-v' for other uses. I agree that this would be more complicated than necessary. It would be better to just drop the default usage of '-v'. This way we wouldn't need a deprecation procedure either. -- Tobias
On Sun, Apr 18, 2010 at 3:31 AM, Tobias Herp
To put it short: *Argparse should simply do this like optparse does already.* I.e., use '--version', '--help' and '-h' by default, but not '-v'. [snip] What happened was the following: Completely unnecessarily, the 'version' constructor argument is now deprecated. [snip] The deprecation of the 'version' argument press-gangs people to replace it by parser.add_argument('--version', action='version', version='<the version>', # the only common part help="show program's version number and exit")
What Tobias has conveniently omitted is that there was not much agreement on what the default behavior of the version flag should be. Things that were proposed: * Use both -v and --version * Use both -V and --version * Use just --version * Print out just the version string * Print out program name with the version string I put up a poll and asked people for feedback on some of the alternatives: http://www.vizu.com/res/Grab-bag/argparse/poll-results.html?n=192933 And it was far from a consensus. Given the lack of consensus, the many different options people thought were the "right" way to do things, and the fact that the action='version' approach allows people to customize the flags to whatever they want, I stick by my decision to deprecate the constructor argument and redirect people to the more flexible add_argument approach. In the face of ambiguity, refuse the temptation to guess. In general, I should say that I'm not opposed to changing the behavior in Python trunk, even if it causes a bit of backwards incompatibility. But I'd really like a consensus about the correct behavior, and so far I have not seen that. Steve -- Where did you get that preposterous hypothesis? Did Steve tell you that? --- The Hiphopopotamus
Steven Bethard schrieb:
On Sun, Apr 18, 2010 at 3:31 AM, Tobias Herp
wrote: To put it short: *Argparse should simply do this like optparse does already.* I.e., use '--version', '--help' and '-h' by default, but not '-v'. [snip] What happened was the following: Completely unnecessarily, the 'version' constructor argument is now deprecated. [snip] The deprecation of the 'version' argument press-gangs people to replace it by parser.add_argument('--version', action='version', version='<the version>', # the only common part help="show program's version number and exit")
What Tobias has conveniently omitted is that there was not much agreement on what the default behavior of the version flag should be.
Well, the mail was quite long already, and the issue-tracker issue was linked.
Things that were proposed:
* Use both -v and --version
This is very unusual. I don't know of a single example other than existing argparse. Incompatible to existing optparse usage.
* Use both -V and --version
A very common combination; many programs which support --version accompany it with -V. However, if we'd add '-V' to the default option strings, we would likely break existing programs which worked around the so-far default.
* Use just --version
IMO the only way, and the way optparse does it.
* Print out just the version string * Print out program name with the version string
If this is an issue: With optparse, the version argument value is printed, which is often something like '%prog '+VERSION (for argparse, '%(prog)s '+VERSION or '%%(prog)s %s' % VERSION). This way, the decision is left to the programmer. Completely agreeable, as far as I'm concerned.
I put up a poll [...]
Given the lack of consensus, the many different options people thought were the "right" way to do things, and the fact that the action='version' approach allows people to customize the flags to whatever they want, I stick by my decision to deprecate the constructor argument ...
A. Very. Bad. Idea.
... and redirect people to the more flexible add_argument approach.
It is ok to /allow/ people to customize the flags to whatever they want. It is /not/ ok to /force/ them to do so, if there is a perfectly reasonable solution which allows them to stick with their habits. And there is one: drop the '-v' default. The only way (see above).
In the face of ambiguity, refuse the temptation to guess.
No guessing is needed (and the ZoP aphorism is not applicable here: this is not about guessing what the user might have meant. Besides, if the user specifies '--version', [s]he /very/ likely wants some info about the program version; giving '-v' can have been done looking forward to --verbose output (ok, nothing bad will happen, but it mismatches user expectations).
In general, I should say that I'm not opposed to changing the behavior in Python trunk, even if it causes a bit of backwards incompatibility.
A /very little/ bit. When fetching stdout to get the program version, it is much more reasonable to rely on '--version' than on '-v'. This is /the/ option string which is best supported by far.
But I'd really like a consensus about the correct behavior, and so far I have not seen that.
We'll have one ;-) -- Tobias
On Sun, Apr 18, 2010 at 2:35 PM, Tobias Herp
Steven Bethard schrieb:
On Sun, Apr 18, 2010 at 3:31 AM, Tobias Herp
wrote: *Argparse should simply do this like optparse does already.* I.e., use '--version', '--help' and '-h' by default, but not '-v'. [snip] The deprecation of the 'version' argument press-gangs people to replace it by parser.add_argument('--version', action='version', version='<the version>', # the only common part help="show program's version number and exit")
What Tobias has conveniently omitted is that there was not much agreement on what the default behavior of the version flag should be. [snip a bunch of Tobias's opinions on what the default should be]
But I'd really like a consensus about the correct behavior, and so far I have not seen that.
We'll have one ;-)
I hope you can understand that I don't consider your personal opinion alone as a consensus. As I said, I'm willing to change the defaults and even break backwards compatibility a bit in Python trunk[1] but I need to a see a consensus from a variety of developers that "--version" is the right answer, and not "-V/--version", etc. Note that even though I agree with you that "-v/--version" is probably not the best choice, in the poll[2] 11% of people still wanted this. So it's not a simple decision. By the way, we could simplify the typical add_argument usage by adding "show program's version number and exit" as the default help for the 'version' action. Then you should just write: parser.add_argument('--version', action='version', version='<the version>') Steve [1] Assuming the release manager will allow it. [2] http://www.vizu.com/res/Grab-bag/argparse/poll-results.html?n=192933 -- Where did you get that preposterous hypothesis? Did Steve tell you that? --- The Hiphopopotamus
Steven Bethard
I need to a see a consensus from a variety of developers that "--version" is the right answer, and not "-V/--version", etc.
Both are ok for me. "-v" as a shortcut for "--version" looks wrong, though. "-v" is almost always used for verbosity these days.
Note that even though I agree with you that "-v/--version" is probably not the best choice, in the poll[2] 11% of people still wanted this.
This strikes me as a small minority. Regards Antoine.
On 19/04/2010 00:52, Antoine Pitrou wrote:
Steven Bethard
writes: I need to a see a consensus from a variety of developers that "--version" is the right answer, and not "-V/--version", etc.
Both are ok for me. "-v" as a shortcut for "--version" looks wrong, though. "-v" is almost always used for verbosity these days.
Adding -V *could* be incompatible with existing users using it for something else. A default '--version' seems like a sensible solution to me. Michael
Note that even though I agree with you that "-v/--version" is probably not the best choice, in the poll[2] 11% of people still wanted this.
This strikes me as a small minority.
Regards
Antoine.
_______________________________________________ Python-Dev mailing list Python-Dev@python.org http://mail.python.org/mailman/listinfo/python-dev Unsubscribe: http://mail.python.org/mailman/options/python-dev/fuzzyman%40voidspace.org.u...
On Sun, Apr 18, 2010 at 3:52 PM, Antoine Pitrou
Steven Bethard
writes: Note that even though I agree with you that "-v/--version" is probably not the best choice, in the poll[2] 11% of people still wanted this.
This strikes me as a small minority.
Agreed, but it's also the current behavior, and has been since the beginning of argparse. Note that no one complained about it until Tobias filed the issue in Nov 06, 2009. Steve -- Where did you get that preposterous hypothesis? Did Steve tell you that? --- The Hiphopopotamus
Steven Bethard schrieb:
On Sun, Apr 18, 2010 at 3:52 PM, Antoine Pitrou
wrote: Steven Bethard
writes: Note that even though I agree with you that "-v/--version" is probably not the best choice, in the poll[2] 11% of people still wanted this.
This strikes me as a small minority.
Agreed, but it's also the current behavior, ...
The current /broken, non-standard/ behaviour. For keeping a current status quo, this is an even worse poll. Very likely some of these voted for this choice because they were afraid of changes (unnecessarily, as explained before).
... and has been since the beginning of argparse.
It's not my fault that in the beginning apparently nobody cared about existing conventions.
Note that no one complained about it until Tobias filed the issue in Nov 06, 2009.
This is not an argument at all. I have collected lots of examples of widely used programs and their options. The only example of '-v', '--verbose' is argparse. It is vital we meet user expectations, and that we support developers in producing programs that do so. -- Tobias
Tobias Herp
Steven Bethard schrieb:
On Sun, Apr 18, 2010 at 3:52 PM, Antoine Pitrou
wrote: Steven Bethard
writes: Note that even though I agree with you that "-v/--version" is probably not the best choice, in the poll[2] 11% of people still wanted this.
This strikes me as a small minority.
Agreed, but it's also the current behavior, ...
The current /broken, non-standard/ behaviour.
I think that is overstating your case. Steven is pointing out the fact that “default to ‘-v’ and ‘--version’” is the current behaviour for argparse. It's also a fact that argparse, as a third-party library, has an existing user base, and changing this behaviour incompatibly is not something to do lightly. To call this behaviour “broken” is a stretch too far, IMO. It does break compatibility with optparse, but it's not *inherently* broken as the above would imply. Nor is there really a standard for this behaviour to be measured “non-standard”. At best, there is a strong convention among Unix command-line programs of ‘--version’ for a version action and ‘-v’ for enabling verbose output. But that convention is not normative, so it's too much to call it a standard IMO.
I have collected lots of examples of widely used programs and their options. The only example of '-v', '--verbose' is argparse.
I'm not sure what programs you're talking about (argparse is a library, not a program that can be run by itself), but in a brief search of my system I've found several programs that use ‘-v’ for a version action, including among others: * Info-ZIP's ‘zip’ and ‘unzip’ * GNU ‘fdisk’ * Vim's ‘xxd’ * W3C's ‘tidy’ These are certainly widely deployed, although they may not be widely familiar. I do agree that such programs are a small minority, but it's overstating your case to call them “non-standard”, since there's no standard for this, or “broken”, since they demonstrably work fine. Rather, they buck what is certainly a firm convention to avoid ‘-v’ for a version option. I'm certainly in favour of preserving that convention by avoiding use of ‘-v’ for version. I would rather, though, that the discussion remain aware of facts and not descend into hyperbole. -- \ “Perchance you who pronounce my sentence are in greater fear | `\ than I who receive it.” —Giordano Bruno, burned at the stake by | _o__) the Catholic church for the heresy of heliocentrism, 1600-02-16 | Ben Finney
On Sun, Apr 18, 2010 at 6:24 PM, Steven Bethard
On Sun, Apr 18, 2010 at 3:52 PM, Antoine Pitrou
wrote: Steven Bethard
writes: Note that even though I agree with you that "-v/--version" is probably not the best choice, in the poll[2] 11% of people still wanted this.
This strikes me as a small minority.
Agreed, but it's also the current behavior, and has been since the beginning of argparse. Note that no one complained about it until Tobias filed the issue in Nov 06, 2009.
I encountered this problem within minutes of first using argparse. Of course I'm very familiar with optparse and the standard optparse instantiation flies off my fingers without thinking. But then there's going to be a lot more people with that background using argparse once it is in the standard library -- people who don't really care about argparse or optparse but just want to use the standard thing. I don't see any reason why argparse can't simply do exactly what optparse did. There's nothing wrong with it. It's what many people expect. We should just defer to tradition when the choice isn't important (it's getting to be a very bike shed thread). Somewhat relatedly, what is the plan for past and future argparse releases? Michael Foord for instance is releasing unittest improvements in parallel under the name unittest2. I believe there is strong disfavor with releasing packages that overlap with the standard library, so continuing to release argparse under the name argparse will cause problems. I would hate to see release complications or confusions keep argparse from seeing future development. -- Ian Bicking | http://blog.ianbicking.org
On Sun, Apr 18, 2010 at 7:02 PM, Ian Bicking
Somewhat relatedly, what is the plan for past and future argparse releases?
I currently don't have any plans to make releases outside of the main Python releases. Perhaps if there's great demand for it, I'll reconsider, but as it is, I haven't had as much time as I would like for argparse, and managing two different types of releases is probably unrealistic for me at the moment. Steve -- Where did you get that preposterous hypothesis? Did Steve tell you that? --- The Hiphopopotamus
On 18Apr2010 22:52, Antoine Pitrou
Cameron Simpson wrote:
On 18Apr2010 22:52, Antoine Pitrou
wrote: | Steven Bethard writes: | > I | > need to a see a consensus from a variety of developers that | > "--version" is the right answer, and not "-V/--version", etc. | | Both are ok for me. "-v" as a shortcut for "--version" looks wrong, though. | "-v" is almost always used for verbosity these days. My view is the same.
I don't expect -v to be one or the other, and I certainly don't expect the rest of the world to want to confirm to what the Python community decides. regards Steve -- Steve Holden +1 571 484 6266 +1 800 494 3119 See PyCon Talks from Atlanta 2010 http://pycon.blip.tv/ Holden Web LLC http://www.holdenweb.com/ UPCOMING EVENTS: http://holdenweb.eventbrite.com/
Steven Bethard wrote:
By the way, we could simplify the typical add_argument usage by adding "show program's version number and exit" as the default help for the 'version' action. Then you should just write:
parser.add_argument('--version', action='version', version='<the version>')
With that change, I would have no problem with the current argparse behaviour (since doing it this way makes it very easy for people to add a "-V" shortcut if they want one). Cheers, Nick. -- Nick Coghlan | ncoghlan@gmail.com | Brisbane, Australia ---------------------------------------------------------------
On Sun, Apr 18, 2010 at 3:57 PM, Nick Coghlan
Steven Bethard wrote:
By the way, we could simplify the typical add_argument usage by adding "show program's version number and exit" as the default help for the 'version' action. Then you should just write:
parser.add_argument('--version', action='version', version='<the version>')
With that change, I would have no problem with the current argparse behaviour (since doing it this way makes it very easy for people to add a "-V" shortcut if they want one).
Probably this should happen regardless of the outcome of the constructor argument. The only reason it wasn't already there is that I hadn't thought of it. ;-) Steve -- Where did you get that preposterous hypothesis? Did Steve tell you that? --- The Hiphopopotamus
Steven Bethard wrote:
On Sun, Apr 18, 2010 at 3:57 PM, Nick Coghlan
wrote: Steven Bethard wrote:
By the way, we could simplify the typical add_argument usage by adding "show program's version number and exit" as the default help for the 'version' action. Then you should just write:
parser.add_argument('--version', action='version', version='<the version>') With that change, I would have no problem with the current argparse behaviour (since doing it this way makes it very easy for people to add a "-V" shortcut if they want one).
Probably this should happen regardless of the outcome of the constructor argument. The only reason it wasn't already there is that I hadn't thought of it. ;-)
Crazy thought... would it make sense to have the following implicitly use "--version" as the option flag: parser.add_argument(action='version', version='<details>') There are two things about the explicit '--version' that bother me: 1. It reduces the automatic provision of "standard" option spellings 2. The repetition in reading/writing 'version' 3 times is kind of annoying (Probably a bad idea, since adding "-V" would mean having to add "--version" as well, but figured it was worth mentioning). Cheers, Nick. -- Nick Coghlan | ncoghlan@gmail.com | Brisbane, Australia ---------------------------------------------------------------
On 04/18/2010 06:35 PM, Nick Coghlan wrote:
Steven Bethard wrote:
On Sun, Apr 18, 2010 at 3:57 PM, Nick Coghlan
wrote: Steven Bethard wrote:
By the way, we could simplify the typical add_argument usage by adding "show program's version number and exit" as the default help for the 'version' action. Then you should just write:
parser.add_argument('--version', action='version', version='<the version>') With that change, I would have no problem with the current argparse behaviour (since doing it this way makes it very easy for people to add a "-V" shortcut if they want one).
Probably this should happen regardless of the outcome of the constructor argument. The only reason it wasn't already there is that I hadn't thought of it. ;-)
Crazy thought... would it make sense to have the following implicitly use "--version" as the option flag:
parser.add_argument(action='version', version='<details>')
There are two things about the explicit '--version' that bother me: 1. It reduces the automatic provision of "standard" option spellings
I think any non standard spellings will either be on purpose or be caught fairly quickly. And in either case I can't imagine it having an impact on the rest of the program, so I wouldn't worry about this too much.
2. The repetition in reading/writing 'version' 3 times is kind of annoying
Ahh, but it isn't the same exact 'version' each time. One is an input specifier string, one is an action key, and the last is a value name.
(Probably a bad idea, since adding "-V" would mean having to add "--version" as well, but figured it was worth mentioning).
I agree. Even though it may seem redundant when writing it, it's both clear and explicit when reading it even if you aren't very familiar with how argparse works, or have just returned from a really long and fun vacation. ;-) Ron
On Sun, Apr 18, 2010 at 4:35 PM, Nick Coghlan
Steven Bethard wrote:
On Sun, Apr 18, 2010 at 3:57 PM, Nick Coghlan
wrote: Steven Bethard wrote:
By the way, we could simplify the typical add_argument usage by adding "show program's version number and exit" as the default help for the 'version' action. Then you should just write:
parser.add_argument('--version', action='version', version='<the version>') With that change, I would have no problem with the current argparse behaviour (since doing it this way makes it very easy for people to add a "-V" shortcut if they want one).
Probably this should happen regardless of the outcome of the constructor argument. The only reason it wasn't already there is that I hadn't thought of it. ;-)
Crazy thought... would it make sense to have the following implicitly use "--version" as the option flag:
parser.add_argument(action='version', version='<details>')
It would be possible, but not simple. The main drawback is that it would have to be done in the parser code, and not in the VersionAction class where all the other version behavior is. I think it's not a huge gain over supplying the option strings, particularly if you're following, say, the Python executable conventions: parser.add_argument('-V', action='version', version='<details>') Steve -- Where did you get that preposterous hypothesis? Did Steve tell you that? --- The Hiphopopotamus
On 04/18/2010 05:57 PM, Nick Coghlan wrote:
Steven Bethard wrote:
By the way, we could simplify the typical add_argument usage by adding "show program's version number and exit" as the default help for the 'version' action. Then you should just write:
parser.add_argument('--version', action='version', version='<the version>')
With that change, I would have no problem with the current argparse behaviour (since doing it this way makes it very easy for people to add a "-V" shortcut if they want one).
+1 This sounds good to me also. Note that the python interpreter uses -V and --version. ra@Gutsy:~$ python3.1 -V Python 3.1.2 ra@Gutsy:~$ python3.1 --version Python 3.1.2 And -v is used as follows: -v : verbose (trace import statements); also PYTHONVERBOSE=x can be supplied multiple times to increase verbosity Ron
On 19 April 2010 04:44, Ron Adam
Note that the python interpreter uses -V and --version.
ra@Gutsy:~$ python3.1 -V Python 3.1.2 ra@Gutsy:~$ python3.1 --version Python 3.1.2
And -v is used as follows:
-v : verbose (trace import statements); also PYTHONVERBOSE=x can be supplied multiple times to increase verbosity
Ironically, I'm forever mistakenly typing "python -v" to get the version. I'm not arguing that this is the "right" behaviour, just pointing out that it's neither unknown, nor entirely surprising to at least one user... As others have pointed out, there's a lot of hyperbole in this thread (not in Ron's post that I quoted, though). If I were using argparse, which I almost certainly will in the future, I'd use the explicit parser.add_argument('--version', action='version', version='<the version>') form, so I have no interest in the default version argument - it can be deprecated, removed, kept the same or changed, it makes no difference to me. Paul.
Steven Bethard wrote:
By the way, we could simplify the typical add_argument usage by adding "show program's version number and exit" as the default help for the 'version' action. Then you should just write:
parser.add_argument('--version', action='version', version='<the version>')
I like this the best. I don't like argparse adding arguments for me. Eric.
Eric Smith schrieb:
Steven Bethard wrote:
By the way, we could simplify the typical add_argument usage by adding "show program's version number and exit" as the default help for the 'version' action. Then you should just write:
parser.add_argument('--version', action='version', version='<the version>')
I like this the best. I don't like argparse adding arguments for me.
There is no reason why you shouldn't get it. You could always (and with optparse as well as argparse) omit the version argument and build or build not the version argument yourself. Or a special add_version_option (hey, it's really an /option/) or add_version_argument method, which would work without if statements and could be overridden in subclasses. But note that - many optparse programs use the version argument - many other programmers find this feature very convenient - dropping or deprecating this is a totally unnecessary change (I have not read a single real reason /why/ this should be done). -- Tobias
- many optparse programs use the version argument - many other programmers find this feature very convenient - dropping or deprecating this is a totally unnecessary change (I have not read a single real reason /why/ this should be done).
You actually brought up a good reason yourself: In the face of ambiguity, refuse the temptation to guess. If you ask "give me a version argument", the question is "how is it spelled?". IIUC, you originally complained that the spelling of argparse (i.e. -v/--version) is not good, and that a different spelling should be used. So it's ambiguous, in which case the feature shouldn't be provided in the first place. Regards, Martin
"Martin v. Löwis" schrieb:
- many optparse programs use the version argument - many other programmers find this feature very convenient - dropping or deprecating this is a totally unnecessary change (I have not read a single real reason /why/ this should be done).
You actually brought up a good reason yourself:
In the face of ambiguity, refuse the temptation to guess.
I didn't guess. The vast majority of *x commandline tools, *including the Python interpreter*, uses '--version' and/or '-V' for the version action, while '-v' is often used for something else, most often verbosity (again: e.g. the Python interpreter). Nobody has argued the converse. The optparse module uses just '--version' option string by default, following the standard.
If you ask "give me a version argument", the question is "how is it spelled?". IIUC, you originally complained that the spelling of argparse (i.e. -v/--version) is not good, and that a different spelling should be used. So it's ambiguous, in which case the feature shouldn't be provided in the first place.
Wrong! Just follow the de-facto standard. There has never been a problem with optparse's version argument, simply because of the fact it conforms with the standard (using just '--version'). Perhaps we wouldn't argue now if they had decided to add '-V' as well, which is AFAIK /never/ used for anything else than the version, either; perhaps this would have been adopted by argparse as well. The optik/optparse people didn't, and the argparse people apparently didn't really look out what options look like in the wild. There is *no* problem with a 'version' argument (which has always been *optional*; nobody is forced to use it) which simply defines the '--version' option to trigger the version option. There has *never* been a problem with the optparse way to do it! Now argparse wants to become a part of Python's standard library; it certainly has advantages over optparse. But the user won't be interested in the difference: "Oh, I see, this is an argparse-based program, so the '-v' is naturally not available for verbosity. Fine!" Up to today, the argparse module had a limited audience. When becoming part of Python, it must follow standards; it should Do The Right Thing by default, and it should keep the usage difference to optparse as small as possible. People should be allowed to rely on the fact that /Python scripts follow the standards/; this is a huge usability gain. Thus, argparse should *continue* to support the version argument, because it is convenient (we use Python because it is convenient!), and it is sufficient in 95% of the cases (I have written lots of optparse scripts, and in exactly one case I wrote the version output myself). It should discontinue the '-v' short option string, because it is non-standard, and it is ambiguous; it is often used for something else, while '-V' isn't (but adding this as a default would like break existing argparse programs, so this is not an option). If the community feels this is necessary, the '-v' could be supported 'invisibly': it should not be visible in the help, and it must not block the usage of '-v' for other purposes. -- Tobias
Tobias Herp writes:
(we use Python because it is convenient!),
Speak for yourself, I want no part of that "we". I use Python because it's well defined and well documented and makes sense and provides powerful operations and runs quickly enough in those applications where I use it. The fact that it's not excessively inconvenient despite an avowed bias toward EIBTI is the icing, not the cake. Remember, convenience is explicitly subsidiary: "not every 3 line function needs to be a builtin." I have no particular opinion the rest of the debate.
On Apr 18, 2010, at 07:30 PM, Eric Smith wrote:
Steven Bethard wrote:
By the way, we could simplify the typical add_argument usage by adding "show program's version number and exit" as the default help for the 'version' action. Then you should just write:
parser.add_argument('--version', action='version', version='<the version>')
I like this the best. I don't like argparse adding arguments for me.
I concur. This gives me all the flexibility I need to make my programs accept exactly the arguments I want and print exactly the information I want to present. -Barry
Barry Warsaw schrieb:
On Apr 18, 2010, at 07:30 PM, Eric Smith wrote:
Steven Bethard wrote:
By the way, we could simplify the typical add_argument usage by adding "show program's version number and exit" as the default help for the 'version' action. Then you should just write:
parser.add_argument('--version', action='version', version='<the version>')
I like this the best. I don't like argparse adding arguments for me.
I concur. This gives me all the flexibility I need to make my programs accept exactly the arguments I want and print exactly the information I want to present.
But you had this possibility all the time! No deprecation or removal of the simple and convenient 'version' argument is needed for this. Just omit it, and build your version action yourself. But please notice that there are others who appreciate this simple way to do it and don't need more. -- Tobias
Tobias Herp wrote:
No deprecation or removal of the simple and convenient 'version' argument is needed for this. Just omit it, and build your version action yourself. But please notice that there are others who appreciate this simple way to do it and don't need more.
One Obvious Way. In this case, the ambiguity of the "version=" argument is sufficient to elevate it to the level of "attractive nuisance" (particularly given the legacy behaviour of conflicting with typical verbosity options). The default help for the action needs to be fixed, and there are a couple of documentation tweaks to be made, but Steven's decision to remove the feature has a sound rationale. Cheers, Nick. -- Nick Coghlan | ncoghlan@gmail.com | Brisbane, Australia ---------------------------------------------------------------
Nick Coghlan wrote:
Tobias Herp wrote:
No deprecation or removal of the simple and convenient 'version' argument is needed for this. Just omit it, and build your version action yourself. But please notice that there are others who appreciate this simple way to do it and don't need more.
One Obvious Way.
In this case, the ambiguity of the "version=" argument is sufficient to elevate it to the level of "attractive nuisance" (particularly given the legacy behaviour of conflicting with typical verbosity options). The default help for the action needs to be fixed, and there are a couple of documentation tweaks to be made, but Steven's decision to remove the feature has a sound rationale.
Exactly my feelings. IMO, straight removal would be fine as well, but a deprecation may be more user-friendly, wrt. the existing code base. Regards, Martin
Nick Coghlan schrieb:
Tobias Herp wrote:
No deprecation or removal of the simple and convenient 'version' argument is needed for this. Just omit it, and build your version action yourself. But please notice that there are others who appreciate this simple way to do it and don't need more.
One Obvious Way.
One /Obvious/ Way! To simply check off the "give the program a version" task, /this/ (the version argument) is the way to do it (obvious enough for legions of programmers who are able to use optparse). If you need a more fancy version action, of course, you need to take care of that yourself.
In this case, the ambiguity of the "version=" argument ...
What /is/ this ambiguity of the "version=" argument? There is none! Do it the way optparse does it, and all is fine! -- Tobias
Tobias Herp wrote:
What /is/ this ambiguity of the "version=" argument? There is none!
Do it the way optparse does it, and all is fine!
All is not fine. How do I add a "-V" shortcut that is equivalent to "--version" as part of an optparse program? (That's a real question, I honestly have no idea how I would do that short of writing my own version display option). Since argparse now uses action='version' instead, the same question becomes trivial (just list "-V" as one of the accepted options for that action). There are at least three reasonable approaches for version options (ignoring the fact that Windows users expect their options to start with a '/' instead of a '-'): - just "--version" (the optparse way) - "-V" and "--version" (the Python interpreter way) - "-v" and "--version" (the old argparse way) The third is by far the least common of the three, but even you admit both of the first two are quite common and acceptable according to the de facto "standard". Optparse makes it easy to do it the optparse way, but difficult to support either of the other formats. Argparse used to be in a similar boat, where only the third option was easy. The latest argparse approach is straightforward regardless of the particular spelling you happen to prefer. Since getting away from the "thou shalt" preachiness of optparse is one of the big reasons for adding argparse in the first place, it seems odd to complain when it switches to a more consistent and flexible API. There were a couple of issues to be addressed with the implementation and the documentation, but the basic approach is sound. Cheers, Nick. -- Nick Coghlan | ncoghlan@gmail.com | Brisbane, Australia ---------------------------------------------------------------
Steven Bethard schrieb:
On Sun, Apr 18, 2010 at 2:35 PM, Tobias Herp
wrote: Steven Bethard schrieb:
On Sun, Apr 18, 2010 at 3:31 AM, Tobias Herp
wrote: *Argparse should simply do this like optparse does already.* I.e., use '--version', '--help' and '-h' by default, but not '-v'. [snip] The deprecation of the 'version' argument press-gangs people to replace it by parser.add_argument('--version', action='version', version='<the version>', # the only common part help="show program's version number and exit")
What Tobias has conveniently omitted is that there was not much agreement on what the default behavior of the version flag should be. [snip a bunch of Tobias's opinions on what the default should be]
But I'd really like a consensus about the correct behavior, and so far I have not seen that.
We'll have one ;-)
I hope you can understand that I don't consider your personal opinion alone as a consensus.
Be careful. There have been other personal opinions, and there are very many *X programs which form a standard which should be followed, and this is a /very strong/ argument, IMO. What you conveniently omitted is that I collected a lot of examples and commented the choices (part of which were part of your poll). Unfortunately you completely ignored these very prosaic arguments. By the way, I just had a look at your poll (currently 81 votes). Correct me if I'm wrong, but... - AFAICS, you didn't provide your audience with any background information, e.g. - how optparse does it (and migration should be as easy as possible, right?) - the existing de-facto standard "--version [-V]" - the choice which reflects my proposal got the most votes (46.9% currently) - 42.0% voted for dropping the version argument, which is a minority (bzw., do you really think the 46.9% would like the version argument to be deprecated?!) which apparently didn't consider the optparse migration/analogy issue. Furthermore, nobody who dislikes the version feature is forced to use it. If 60% had voted for removal of a feature which is important and convenient for 40%, would you remove it? Really? IMO, removal of a feature which is used by 40% is out of the question; and if removal is, deprecation is as well. Back to the actual numbers: dropping the argument is impossible (/and so is deprecation/); drop the 42.0%. Take the remaining numbers: 46.9% voted for the change, and 11.1% against it. Do you take your own poll seriously? -- Tobias
Tobias Herp wrote:
Be careful. There have been other personal opinions, and there are very many *X programs which form a standard which should be followed, and this is a /very strong/ argument, IMO.
If the "version=" argument were to only provide "--version", how would you conveniently add a "-V" shorthand? This is trivial with the add_argument approach, but less straightforward with a "version=" argument to the parser constructor. People that want "-v" to mean verbosity in 2.x can also trivially pass "conflict_handler='resolve'" to override the implicitly created version shorthand. Would it be more convenient if argparse had never deviated from the GNU and optparse command line conventions in this respect? Sure it would be. But given that it did, a 'version' action that makes it trivial to choose the details of your version flags is a decent alternative approach to a now-ambiguous version argument to the parser constructor (especially once the default help string for the option is added). Note there are two changes I believe should be made to the argparse documentation for 2.7 though: - the '--version' example should either not use a shorthand, or should use the conventional '-V' - this issue needs to be mentioned in the section on migrating from optparse. Cheers, Nick. -- Nick Coghlan | ncoghlan@gmail.com | Brisbane, Australia ---------------------------------------------------------------
On Sun, Apr 18, 2010 at 6:40 PM, Nick Coghlan
Note there are two changes I believe should be made to the argparse documentation for 2.7 though: - the '--version' example should either not use a shorthand, or should use the conventional '-V' - this issue needs to be mentioned in the section on migrating from optparse.
Thanks for pointing these out. I'll make a note to fix these when I fix the default help value. Steve -- Where did you get that preposterous hypothesis? Did Steve tell you that? --- The Hiphopopotamus
Tobias Herp wrote:
Steven Bethard schrieb:
On Sun, Apr 18, 2010 at 2:35 PM, Tobias Herp
wrote: Steven Bethard schrieb:
On Sun, Apr 18, 2010 at 3:31 AM, Tobias Herp
wrote: *Argparse should simply do this like optparse does already.* I.e., use '--version', '--help' and '-h' by default, but not '-v'. [snip] The deprecation of the 'version' argument press-gangs people to replace it by parser.add_argument('--version', action='version', version='<the version>', # the only common part help="show program's version number and exit") What Tobias has conveniently omitted is that there was not much agreement on what the default behavior of the version flag should be. [snip a bunch of Tobias's opinions on what the default should be] But I'd really like a consensus about the correct behavior, and so far I have not seen that. We'll have one ;-) I hope you can understand that I don't consider your personal opinion alone as a consensus.
Be careful. There have been other personal opinions, and there are very many *X programs which form a standard which should be followed, and this is a /very strong/ argument, IMO.
What you conveniently omitted is that I collected a lot of examples and commented the choices (part of which were part of your poll). Unfortunately you completely ignored these very prosaic arguments.
By the way, I just had a look at your poll (currently 81 votes). Correct me if I'm wrong, but... - AFAICS, you didn't provide your audience with any background information, e.g. - how optparse does it (and migration should be as easy as possible, right?) - the existing de-facto standard "--version [-V]" - the choice which reflects my proposal got the most votes (46.9% currently) - 42.0% voted for dropping the version argument, which is a minority (bzw., do you really think the 46.9% would like the version argument to be deprecated?!) which apparently didn't consider the optparse migration/analogy issue.
Furthermore, nobody who dislikes the version feature is forced to use it. If 60% had voted for removal of a feature which is important and convenient for 40%, would you remove it? Really? IMO, removal of a feature which is used by 40% is out of the question; and if removal is, deprecation is as well.
Back to the actual numbers: dropping the argument is impossible (/and so is deprecation/); drop the 42.0%. Take the remaining numbers: 46.9% voted for the change, and 11.1% against it.
Do you take your own poll seriously?
When was this ever a democracy? regards Steve -- Steve Holden +1 571 484 6266 +1 800 494 3119 See PyCon Talks from Atlanta 2010 http://pycon.blip.tv/ Holden Web LLC http://www.holdenweb.com/ UPCOMING EVENTS: http://holdenweb.eventbrite.com/
On 4/18/2010 9:44 PM, Steve Holden wrote:
Tobias Herp wrote:
Steven Bethard schrieb:
On Sun, Apr 18, 2010 at 2:35 PM, Tobias Herp
wrote: Steven Bethard schrieb:
But I'd really like a consensus about the correct behavior, and so far I have not seen that.
Do you take your own poll seriously?
When was this ever a democracy?
Is consensus superficial? -- Scott Dial scott@scottdial.com scodial@cs.indiana.edu
On 19/04/2010 21:19, Scott Dial wrote:
On 4/18/2010 9:44 PM, Steve Holden wrote:
Tobias Herp wrote:
Steven Bethard schrieb:
On Sun, Apr 18, 2010 at 2:35 PM, Tobias Herp
wrote: Steven Bethard schrieb:
But I'd really like a consensus about the correct behavior, and so far I have not seen that.
Do you take your own poll seriously?
When was this ever a democracy?
Is consensus superficial?
No, but it isn't always possible or necessary. In general the maintainer of a module should make the best decision, not the one with the most backing. :-) All the best, Michael -- http://www.ironpythoninaction.com/
On Mon, Apr 19, 2010 at 12:51 PM, Michael Foord
On 19/04/2010 21:19, Scott Dial wrote:
Is consensus superficial?
No, but it isn't always possible or necessary. In general the maintainer of a module should make the best decision, not the one with the most backing. :-)
Yep, that was my logic. With 42% vs. 47% I decided there really wasn't consensus, and I should make the decision that I felt was best for argparse. If it had been e.g., 20% vs 80%, I would have bent to the will of the masses regardless of what I thought. Steve -- Where did you get that preposterous hypothesis? Did Steve tell you that? --- The Hiphopopotamus
participants (16)
-
"Martin v. Löwis"
-
Antoine Pitrou
-
Barry Warsaw
-
Ben Finney
-
Cameron Simpson
-
Eric Smith
-
Ian Bicking
-
Michael Foord
-
Nick Coghlan
-
Paul Moore
-
Ron Adam
-
Scott Dial
-
Stephen J. Turnbull
-
Steve Holden
-
Steven Bethard
-
Tobias Herp