This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author paul.j3
Recipients bethard, eric.smith, gcbirzan, jeffknupp, kalt, paul.j3, python-dev, r.david.murray, wt
Date 2013-04-05.21:59:03
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1365199143.92.0.947817397442.issue13922@psf.upfronthosting.co.za>
In-reply-to
Content
There's another 'feature' to the patch proposed here.  It only deletes the first '--' in the list of strings passed to '_get_values' for a particular action.

    parser = argparse.ArgumentParser()
    parser.add_argument('foo')
    parser.add_argument('bar', nargs='*')
    print(parser.parse_args('-- 1 -- 2 3 4'.split(' ')))
    # Namespace(bar=['2', '3', '4'], foo='1')

'_get_values' first gets ('foo',['--','1']), then ('bar',['--','2','3','4'])

    print(parser.parse_args('-- -- 1 -- 2 -- 3 4'.split(' ')))
    # with this '1st only' change
    # Namespace(bar=['1', '2', '--', '3', '4'], foo='--')
    # without it, deleting all '--'; note foo is empty
    # Namespace(bar=['1', '2', '3', '4'], foo=[])

And to confuse things a bit more:

    print(parser.parse_args('1 -- 2 3 4'.split(' ')))
    # Namespace(bar=['2', '3', '4'], foo='1')

passes ['1','--'] with 'foo'

If 'bar' nargs='...', bar gets all of the '--' (with or without this patch).

The handling of '--' is complex because it is used in one place to mean, 'everything else is an argument', effectively adding '-AA...' to the arg_strings_pattern. It also matches with the nargs_pattern (e.g. '(-*A-*)...').  And then it may or may not be removed in _get_values().
History
Date User Action Args
2013-04-05 21:59:03paul.j3setrecipients: + paul.j3, bethard, eric.smith, kalt, r.david.murray, python-dev, wt, jeffknupp, gcbirzan
2013-04-05 21:59:03paul.j3setmessageid: <1365199143.92.0.947817397442.issue13922@psf.upfronthosting.co.za>
2013-04-05 21:59:03paul.j3linkissue13922 messages
2013-04-05 21:59:03paul.j3create