classification
Title: getopt should not accept no_argument that ends with '='
Type: behavior Stage: commit review
Components: Library (Lib) Versions: Python 3.1, Python 3.2, Python 2.7
process
Status: closed Resolution: fixed
Dependencies: Superseder:
Assigned To: Nosy List: BreamoreBoy, amaury.forgeotdarc, vstinner, wangchun
Priority: normal Keywords: patch

Created on 2008-12-11 06:54 by wangchun, last changed 2010-07-24 01:13 by vstinner. This issue is now closed.

Files
File name Uploaded Description Edit
getopt.py.diff wangchun, 2008-12-11 07:12
getopt-2.patch vstinner, 2009-03-27 01:28
Messages (7)
msg77597 - (view) Author: Wang Chun (wangchun) Date: 2008-12-11 06:54
Consider the following program tmp.py:

import sys, getopt
print(getopt.getopt(sys.argv[1:], '', ['help']))

The program accept "--help" without a value:

python helloworld.py --help

But if someone invoke the program like:

python helloworld.py --help=

Python should raise an error.

"--help=" is not considered as no_argument in libc's getopt implementation (tested on Mac OS X 
Leopard):

#include <getopt.h>

static struct option longopts[] = { 
        { "help", no_argument, NULL, "h" },
};

#include <getopt.h>

static struct option longopts[] = { 
        { "help", no_argument, NULL, 'h' },
};

int main(int argc, char **argv)
{
        while (getopt_long(argc, argv, "h", longopts, NULL) != -1);
        return 0;
}

macbook:~/tmp$ gcc -o tmp tmp.c
macbook:~/tmp$ ./tmp --help=
tmp: option `--help' doesn't allow an argument
macbook:~/tmp$
msg78283 - (view) Author: STINNER Victor (vstinner) * (Python committer) Date: 2008-12-25 23:20
Can you please also write a regression test in 
Lib/test/test_getopt.py?
msg84247 - (view) Author: STINNER Victor (vstinner) * (Python committer) Date: 2009-03-27 01:28
Updated patch with a regression test.
msg84276 - (view) Author: Amaury Forgeot d'Arc (amaury.forgeotdarc) * (Python committer) Date: 2009-03-27 17:04
The patch is good.
msg108199 - (view) Author: Mark Lawrence (BreamoreBoy) * Date: 2010-06-19 18:32
I'm not sure why this is still open, would somebody like to comment, see also Issue4650.
msg111394 - (view) Author: Mark Lawrence (BreamoreBoy) * Date: 2010-07-23 21:55
msg84276 "the patch is good".  What is the problem with committing this?
msg111406 - (view) Author: STINNER Victor (vstinner) * (Python committer) Date: 2010-07-24 01:13
Fixed in 3.2 (r83116), 2.7 (r83117), 3.1 (r83118) and 2.6 (r83119).
History
Date User Action Args
2010-07-24 01:13:18vstinnersetstatus: open -> closed
resolution: accepted -> fixed
messages: + msg111406
2010-07-23 21:55:44BreamoreBoysetmessages: + msg111394
2010-07-09 01:28:24BreamoreBoysetstage: commit review
versions: + Python 3.2, - Python 2.6, Python 3.0
2010-06-19 18:32:48BreamoreBoysetnosy: + BreamoreBoy
messages: + msg108199
2009-03-27 17:04:10amaury.forgeotdarcsetresolution: accepted

messages: + msg84276
nosy: + amaury.forgeotdarc
2009-03-27 01:28:56vstinnersetfiles: + getopt-2.patch

messages: + msg84247
2008-12-25 23:20:10vstinnersetnosy: + vstinner
messages: + msg78283
2008-12-20 14:28:46loewissetversions: - Python 2.5, Python 2.4, Python 2.3, Python 2.2.3, Python 2.2.2, Python 2.2.1, Python 2.2, Python 2.1.2, Python 2.1.1, Python 2.5.3
2008-12-11 07:12:45wangchunsetfiles: + getopt.py.diff
keywords: + patch
2008-12-11 06:54:17wangchuncreate