Skip to content

argparse: PARSER option for nargs not documented #61192

Closed

Description

@Robert
mannequin
BPO 16988
Nosy @bitdancer, @cjerdonek

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 2017-09-04.17:45:19.932>
created_at = <Date 2013-01-17.21:30:15.039>
labels = ['invalid', 'docs']
title = 'argparse: PARSER option for nargs not documented'
updated_at = <Date 2017-09-04.17:45:19.926>
user = 'https://bugs.python.org/Robert'

bugs.python.org fields:

activity = <Date 2017-09-04.17:45:19.926>
actor = 'r.david.murray'
assignee = 'docs@python'
closed = True
closed_date = <Date 2017-09-04.17:45:19.932>
closer = 'r.david.murray'
components = ['Documentation']
creation = <Date 2013-01-17.21:30:15.039>
creator = 'Robert'
dependencies = []
files = []
hgrepos = []
issue_num = 16988
keywords = []
message_count = 4.0
messages = ['180155', '180195', '187140', '301233']
nosy_count = 7.0
nosy_names = ['bethard', 'r.david.murray', 'chris.jerdonek', 'docs@python', 'paul.j3', 'jeffknupp', 'Robert']
pr_nums = []
priority = 'normal'
resolution = 'not a bug'
stage = 'resolved'
status = 'closed'
superseder = None
type = None
url = 'https://bugs.python.org/issue16988'
versions = ['Python 3.4']

Activity

  1. Robert commented on Jan 17, 2013

    Robertmannequin
    MannequinAuthor

    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.

  2. jeffknupp commented on Jan 18, 2013

    jeffknuppmannequin
    Mannequin

    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.

  3. paulj3 commented on Apr 17, 2013

    paulj3mannequin
    Mannequin

    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.

  4. bitdancer commented on Sep 4, 2017

    @bitdancer
    Member

    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.

  5. added and removed
    type-featureA feature request or enhancement
    on Sep 4, 2017
  6. transferred this issue fromon Apr 10, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    docsDocumentation in the Doc dir

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions