msg77668 - (view) |
Author: Krzysztof Szawala (kszawala) |
Date: 2008-12-12 14:14 |
I am using optparse for command-line parameters parsing. To follow common naming convention I defined -d (minus followed by a single character option) and --debug (double minus followed by a word). It looks like optparse doesn't complain when -debug (single minus) is specified and morover it doesn't recognize it as --debug. I am using Python 2.5.2. Problem was observed on Linux but also occurs on Windows. |
|
|
msg77683 - (view) |
Author: David W. Lambert (LambertDW) |
Date: 2008-12-12 18:32 |
When I use it on python 3 optparse reports no such option -e, which is correct since the form -debug permits a run of single character options. |
|
|
msg77856 - (view) |
Author: Krzysztof Szawala (kszawala) |
Date: 2008-12-15 09:29 |
As I mentionetd, the problem occurs with Python 2.5 (I won't be switching to Python 3). The only perspective for me to upgrade is Python 2.6, but as I can see the problem applies to 2.6 as well. |
|
|
msg77893 - (view) |
Author: Gabriel Genellina (ggenellina) |
Date: 2008-12-16 00:20 |
could you provide a test case / code fragment showing the bug? |
|
|
msg78320 - (view) |
Author: STINNER Victor (vstinner) *  |
Date: 2008-12-26 23:53 |
-debug may be equivalent to -d -e -b -u -g (if none of these options have an argument), but no to --debug. If you like to use -d as an alias to --debug, just use: add_option("-d", "--debug", ...). |
|
|
msg108637 - (view) |
Author: Terry J. Reedy (terry.reedy) *  |
Date: 2010-06-25 22:07 |
Victor, I am interpreting your comment as saying that this is not a bug. If I am wrong, someone can re-open. In any case, the bug would have to be in 2.6 or more realistically, 2.7, since 2.6.final will be out soon. |
|
|
msg108638 - (view) |
Author: Éric Araujo (eric.araujo) *  |
Date: 2010-06-25 22:11 |
optparse specifically supports only GNU-style two-dashes long argument. Victor is right, optparse will always understand -thing as -t -h -i -n -g. |
|
|
msg108656 - (view) |
Author: R. David Murray (r.david.murray) *  |
Date: 2010-06-26 00:02 |
I thought the OP might be saying that -debug didn't throw an error in 2.6. test_optparse doesn't seem to have a test for this, so I wrote one. But as far as I can see the correct error (invalid option -e, given that 'd' is defined) is thrown. In 2.5, as well. Rereading the initial post I understand the problem: his 'd' option takes an argument. So 'ebug' becomes the option value, and thus no error is thrown. Which is working as designed (that's how single letter options that take arguments usually work in Unix) So, it is correct that this is not a bug. |
|
|
msg108699 - (view) |
Author: STINNER Victor (vstinner) *  |
Date: 2010-06-26 10:00 |
> Victor, I am interpreting your comment as saying > that this is not a bug. No, I tried to explain that it is a bug :-) add_option("-debug", "--debug", ...) and add_option("-debug", ...) should raise an error. |
|
|
msg108701 - (view) |
Author: STINNER Victor (vstinner) *  |
Date: 2010-06-26 10:05 |
Reopen: add_option("-debug", "--debug", ...) and add_option("-debug", ...) should raise an error and have a test. |
|
|
msg108702 - (view) |
Author: Éric Araujo (eric.araujo) *  |
Date: 2010-06-26 10:09 |
Oh, we all focused on “-debug is not recognized as --debug” and forgot that the bug report also said “optparse does not complain when -debug is specified” (not sure if that meant “added” or “given on the command line”). We have to check if the bug still applies on 2.6, 2.7, 3.1 and 3.2. |
|
|
msg109213 - (view) |
Author: Éric Araujo (eric.araujo) *  |
Date: 2010-07-04 10:36 |
David committed a unit test in r82233. Who wants to propose a patch now? |
|
|
msg109217 - (view) |
Author: R. David Murray (r.david.murray) *  |
Date: 2010-07-04 14:07 |
I didn't commit a unit test for the revised subject, my unit test was for the previous misunderstood diagnosis. So a unit test for disallowing single dash long options in add_option is still needed. Note that this appears (at least on a quick test) to apply to argparse as well. I've left 2.7 and 3.1 in versions, but I'm not 100% sure this should be backported since it is a behavior change. But it's hard to imagine working code using this (does it even do anything, or is the single dash option just silently ignored?) |
|
|
msg111294 - (view) |
Author: Steven Bethard (bethard) *  |
Date: 2010-07-23 12:25 |
In argparse, "-debug" is a perfectly valid flag (you're not required to have "--debug", and you can even have "+debug" if you want and you specify it correctly), so unless I misunderstand what the bug is, this doesn't apply to argparse. |
|
|
msg111302 - (view) |
Author: R. David Murray (r.david.murray) *  |
Date: 2010-07-23 12:41 |
In that case you are correct, it does not apply to argparse. |
|
|
msg165143 - (view) |
Author: Aaron (hac.man) |
Date: 2012-07-10 02:21 |
I came across this bug report and was unable to reproduce the described behavior. I wrote a few test cases demonstrating that the behavior is indeed correct. It passes both against 2.5.2 (the version described in the report) and the lastest 2.7. The relevant code is line 602 of optparse.py in the function Option._set_opt_strings(). I believe this bug can be closed. |
|
|
msg165557 - (view) |
Author: Roundup Robot (python-dev)  |
Date: 2012-07-16 00:12 |
New changeset 844bb753570f by R David Murray in branch 'default': #4640: Add optparse tests for '-xxx' invalid when defining options. http://hg.python.org/cpython/rev/844bb753570f |
|
|
msg165558 - (view) |
Author: R. David Murray (r.david.murray) *  |
Date: 2012-07-16 00:15 |
Re-reading the issue I think the OP was not trying to define '-debug', but was indeed reporting the behavior when -debug was passed to the parser. I've committed your tests (thanks). So we now have tests for both cases, and this issue can be closed as invalid. |
|
|