You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
error mixing positional and non-positional arguments with argparse #76217
I'm trying to mix positional and non-positional arguments with a script using argparse, but I observe inconsistent behaviour.
The attached test runs fine when invoked with
test_argparse.py --info a a=b
test_argparse.py a a=b --info
but produces the error error: unrecognized arguments: a=b when invoked as
test_argparse.py a --info a=b
Is this intended behaviour ? If yes, is this documented ? If not, is there a way to make this work with existing argparse versions ?
Can you reproduce this without your PosArgsParser?
stefanseefeld commented on Nov 15, 2017
stefanseefeldmannequin
MannequinAuthor
More actions
On 15.11.2017 12:54, R. David Murray wrote:
Can you reproduce this without your PosArgsParser?
I can indeed (by simply commenting out the action argument to the add_argument() calls).
That obviously results in all positional arguments being accumulated in
the goal member, as there is no logic to distinguish a from a=b
semantically.
stefanseefeld commented on Nov 15, 2017
stefanseefeldmannequin
MannequinAuthor
More actions
It looks like https://bugs.python.org/issue14191 is a conversation about the same inconsistent behaviour. It is set to "fixed". Can you comment on this ? Should I follow the advice mentioned there about how to work around the issue ?
Ah, yes, I'd managed to forget about that issue, even though I was the one that finally committed the fix.
So, the alternate parser will be in 3.7. In the meantime you can grab the code from the commit and put it in a local file, I think. You'll doubtless have to tweak a few things to use it that way, but it should be fairly straightforward.
Activity
stefanseefeld commentedon Nov 15, 2017
I'm trying to mix positional and non-positional arguments with a script using
argparse, but I observe inconsistent behaviour.The attached test runs fine when invoked with
test_argparse.py --info a a=b
test_argparse.py a a=b --info
but produces the error
error: unrecognized arguments: a=bwhen invoked astest_argparse.py a --info a=b
Is this intended behaviour ? If yes, is this documented ? If not, is there a way to make this work with existing
argparseversions ?bitdancer commentedon Nov 15, 2017
Can you reproduce this without your PosArgsParser?
stefanseefeld commentedon Nov 15, 2017
On 15.11.2017 12:54, R. David Murray wrote:
stefanseefeld commentedon Nov 15, 2017
It looks like https://bugs.python.org/issue14191 is a conversation about the same inconsistent behaviour. It is set to "fixed". Can you comment on this ? Should I follow the advice mentioned there about how to work around the issue ?
bitdancer commentedon Nov 15, 2017
Ah, yes, I'd managed to forget about that issue, even though I was the one that finally committed the fix.
So, the alternate parser will be in 3.7. In the meantime you can grab the code from the commit and put it in a local file, I think. You'll doubtless have to tweak a few things to use it that way, but it should be fairly straightforward.