Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

getopt should not accept no_argument that ends with '=' #48879

Closed
wangchun mannequin opened this issue Dec 11, 2008 · 7 comments
Closed

getopt should not accept no_argument that ends with '=' #48879

wangchun mannequin opened this issue Dec 11, 2008 · 7 comments
Labels
stdlib Python modules in the Lib dir type-bug An unexpected behavior, bug, or error

Comments

@wangchun
Copy link
Mannequin

wangchun mannequin commented Dec 11, 2008

BPO 4629
Nosy @amauryfa, @vstinner
Files
  • getopt.py.diff
  • getopt-2.patch
  • Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.

    Show more details

    GitHub fields:

    assignee = None
    closed_at = <Date 2010-07-24.01:13:18.886>
    created_at = <Date 2008-12-11.06:54:17.408>
    labels = ['type-bug', 'library']
    title = "getopt should not accept no_argument that ends with '='"
    updated_at = <Date 2010-07-24.01:13:18.883>
    user = 'https://bugs.python.org/wangchun'

    bugs.python.org fields:

    activity = <Date 2010-07-24.01:13:18.883>
    actor = 'vstinner'
    assignee = 'none'
    closed = True
    closed_date = <Date 2010-07-24.01:13:18.886>
    closer = 'vstinner'
    components = ['Library (Lib)']
    creation = <Date 2008-12-11.06:54:17.408>
    creator = 'wangchun'
    dependencies = []
    files = ['12325', '13434']
    hgrepos = []
    issue_num = 4629
    keywords = ['patch']
    message_count = 7.0
    messages = ['77597', '78283', '84247', '84276', '108199', '111394', '111406']
    nosy_count = 4.0
    nosy_names = ['amaury.forgeotdarc', 'vstinner', 'wangchun', 'BreamoreBoy']
    pr_nums = []
    priority = 'normal'
    resolution = 'fixed'
    stage = 'commit review'
    status = 'closed'
    superseder = None
    type = 'behavior'
    url = 'https://bugs.python.org/issue4629'
    versions = ['Python 3.1', 'Python 2.7', 'Python 3.2']

    @wangchun
    Copy link
    Mannequin Author

    wangchun mannequin commented Dec 11, 2008

    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$

    @wangchun wangchun mannequin added stdlib Python modules in the Lib dir type-bug An unexpected behavior, bug, or error labels Dec 11, 2008
    @vstinner
    Copy link
    Member

    Can you please also write a regression test in
    Lib/test/test_getopt.py?

    @vstinner
    Copy link
    Member

    Updated patch with a regression test.

    @amauryfa
    Copy link
    Member

    The patch is good.

    @BreamoreBoy
    Copy link
    Mannequin

    BreamoreBoy mannequin commented Jun 19, 2010

    I'm not sure why this is still open, would somebody like to comment, see also bpo-4650.

    @BreamoreBoy
    Copy link
    Mannequin

    BreamoreBoy mannequin commented Jul 23, 2010

    msg84276 "the patch is good". What is the problem with committing this?

    @vstinner
    Copy link
    Member

    Fixed in 3.2 (r83116), 2.7 (r83117), 3.1 (r83118) and 2.6 (r83119).

    @ezio-melotti ezio-melotti transferred this issue from another repository Apr 10, 2022
    Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
    Labels
    stdlib Python modules in the Lib dir type-bug An unexpected behavior, bug, or error
    Projects
    None yet
    Development

    No branches or pull requests

    2 participants