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
argparse: PARSER option for nargs not documented #61192
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=Noneclosed_at=<Date2017-09-04.17:45:19.932>created_at=<Date2013-01-17.21:30:15.039>labels= ['invalid', 'docs']
title='argparse: PARSER option for nargs not documented'updated_at=<Date2017-09-04.17:45:19.926>user='https://bugs.python.org/Robert'
There is a value for nargs: PARSER="A..." which is not documented at http://docs.python.org/3.4/library/argparse.html#nargs. The docstring for the action class in argparse.py also does not list PARSER as a valid value for nargs.
In argparse.py on line 2199-2201 it says:
# Allow one argument followed by any number of options or arguments
elif nargs == PARSER:
nargs_pattern = '(-A[-AO])'
This is the only hint that I could find on what it is about.
The 'PARSER' nargs choice is an implementation detail as a way to handle subparsers. The parser needs to know that the first value should be handled, but everything that follows will be handled by the subparser.
By using a subparser, you're effectively using 'PARSER', but it wouldn't make sense to allow 'PARSER' to be set directly as it only makes sense when used in conjunction with a subparser.
paulj3 commented on Apr 17, 2013
paulj3mannequin
Mannequin
More actions
I've experimented with an argparse adaptation of profile.py:
parser=argparse.ArgumentParser(usage=usage)
parser.add_argument('-o', '--outfile', dest="outfile",
help="Save stats to <outfile>", metavar="path")
parser.add_argument('-s', '--sort', dest="sort",
help="Sort order when printing to stdout ...",
default=-1)
parser.add_argument('args', nargs=argparse.PARSER,
metavar="scriptfile [arg] ...")
# expect at least one positional, a py module
It is somewhat like subparsers, but without defined subparser choices. Or you could say that PARSER (A...) is to REMAINDER (...) as '+' is to '*'. It requires at least one argument. I could, just as well, have created two arguments, 'scriptfile' and 'args' (with '...').
I don't know if that is an argument for documenting it or not.
I don't think this use case is enough to justify documenting it, since this is not an intuitive meaning of the word PARSER. I think if we wanted to expose this for this kind of use case, we'd want to rename the constant (with an alias for backward compatibility), which would be an enhancement. I'm going to close this, but someone who wants this could open an enhancement request.
Activity
Robert commentedon Jan 17, 2013
There is a value for nargs: PARSER="A..." which is not documented at http://docs.python.org/3.4/library/argparse.html#nargs. The docstring for the action class in argparse.py also does not list PARSER as a valid value for nargs.
In argparse.py on line 2199-2201 it says:
# Allow one argument followed by any number of options or arguments
elif nargs == PARSER:
nargs_pattern = '(-A[-AO])'
This is the only hint that I could find on what it is about.
jeffknupp commentedon Jan 18, 2013
This is not a bug.
The 'PARSER' nargs choice is an implementation detail as a way to handle subparsers. The parser needs to know that the first value should be handled, but everything that follows will be handled by the subparser.
By using a subparser, you're effectively using 'PARSER', but it wouldn't make sense to allow 'PARSER' to be set directly as it only makes sense when used in conjunction with a subparser.
paulj3 commentedon Apr 17, 2013
I've experimented with an argparse adaptation of profile.py:
It is somewhat like subparsers, but without defined subparser choices. Or you could say that PARSER (A...) is to REMAINDER (...) as '+' is to '*'. It requires at least one argument. I could, just as well, have created two arguments, 'scriptfile' and 'args' (with '...').
I don't know if that is an argument for documenting it or not.
bitdancer commentedon Sep 4, 2017
I don't think this use case is enough to justify documenting it, since this is not an intuitive meaning of the word PARSER. I think if we wanted to expose this for this kind of use case, we'd want to rename the constant (with an alias for backward compatibility), which would be an enhancement. I'm going to close this, but someone who wants this could open an enhancement request.