paul j3 added the comment:

I wouldn't describe this as bug, just a nuance on how parsers and subparsers 
play together.
To the main parser, the subparser argument looks like another positional.   It 
allocates strings to it and any following positionals based on their respective 
'nargs'.

The nargs for a subparser is 'A...' (argparse.PARSER), which is similar to '+' 
(it takes one or more strings)

    parser2=ArgumentParser()
    parser2.add_argument('arg1',nargs='A...')
    parser2.add_argument('arg2',nargs='+')
    parser2.parse_args(['create','test','test2'])

produces

    Namespace(arg1=['create', 'test'], arg2=['test2'])

Notice how 2 of the strings are allocated to arg1, and only 1 to arg2. arg2 is 
happy with just 1, so arg1 gets the rest.

In your example it's the subparser that is issuing the 'unrecognized arguments' 
message, because it doesn't have a positional argument that would take it.

Having more than one positional that takes are variable number of arguments is 
tricky.  I find it helpful to think in terms of how `re` would handle a pattern 
like `(A+)(A*)(A)`.

----------
nosy: +paul.j3

_______________________________________
Python tracker <rep...@bugs.python.org>
<http://bugs.python.org/issue24166>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com

Reply via email to