Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

argparse "usage" overly-complex with nargs="*" #82619

Closed
bobjalex mannequin opened this issue Oct 10, 2019 · 11 comments
Closed

argparse "usage" overly-complex with nargs="*" #82619

bobjalex mannequin opened this issue Oct 10, 2019 · 11 comments
Assignees
Labels
3.9 only security fixes stdlib Python modules in the Lib dir type-bug An unexpected behavior, bug, or error

Comments

@bobjalex
Copy link
Mannequin

bobjalex mannequin commented Oct 10, 2019

BPO 38438
Nosy @rhettinger, @ericvsmith, @nicktimko, @brandtbucher, @CallumQuick
PRs
  • bpo-38438: Simplify argparse "star nargs" usage. #17106
  • 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 = 'https://github.com/rhettinger'
    closed_at = <Date 2019-11-12.05:09:42.168>
    created_at = <Date 2019-10-10.20:24:39.001>
    labels = ['type-bug', 'library', '3.9']
    title = 'argparse "usage" overly-complex with nargs="*"'
    updated_at = <Date 2019-11-12.05:09:42.165>
    user = 'https://bugs.python.org/bobjalex'

    bugs.python.org fields:

    activity = <Date 2019-11-12.05:09:42.165>
    actor = 'rhettinger'
    assignee = 'rhettinger'
    closed = True
    closed_date = <Date 2019-11-12.05:09:42.168>
    closer = 'rhettinger'
    components = ['Library (Lib)']
    creation = <Date 2019-10-10.20:24:39.001>
    creator = 'bobjalex'
    dependencies = []
    files = []
    hgrepos = []
    issue_num = 38438
    keywords = ['patch']
    message_count = 11.0
    messages = ['354402', '354410', '354419', '354450', '354457', '354467', '354475', '354476', '356354', '356386', '356411']
    nosy_count = 7.0
    nosy_names = ['rhettinger', 'eric.smith', 'paul.j3', 'bobjalex', 'nicktimko', 'brandtbucher', 'callumquick']
    pr_nums = ['17106']
    priority = 'normal'
    resolution = 'fixed'
    stage = 'resolved'
    status = 'closed'
    superseder = None
    type = 'behavior'
    url = 'https://bugs.python.org/issue38438'
    versions = ['Python 3.9']

    @bobjalex
    Copy link
    Mannequin Author

    bobjalex mannequin commented Oct 10, 2019

    This program:

    import argparse
    ap = argparse.ArgumentParser()
    ap.add_argument("arg", nargs="*")
    ap.parse_args()

    Gives usage message:
    usage: help_complexity.py [-h] [arg [arg ...]]

    It's correct, but unnecessarily complex and challenging to the user.
    If I were manually writing the usage, arg... would do, or maybe [arg ...] to be consistent with other messages??

    @bobjalex bobjalex mannequin added 3.7 (EOL) end of life 3.8 only security fixes stdlib Python modules in the Lib dir type-bug An unexpected behavior, bug, or error labels Oct 10, 2019
    @ericvsmith
    Copy link
    Member

    I think [arg ...] would make sense.

    Removing 3.5 and 3.6, since they're in security only mode. Adding 3.9.

    @ericvsmith ericvsmith added the 3.9 only security fixes label Oct 10, 2019
    @rhettinger
    Copy link
    Contributor

    Bob, would like to create a PR?

    @rhettinger rhettinger self-assigned this Oct 11, 2019
    @brandtbucher
    Copy link
    Member

    I’m happy to write one. This seems like a pretty straightforward fix.

    @rhettinger
    Copy link
    Contributor

    Bob, as OP you get first dibs on a PR.
    Brandt, you're next in line :-)

    @nicktimko
    Copy link
    Mannequin

    nicktimko mannequin commented Oct 11, 2019

    The [arg [arg ...]] feels a bit more formal to me, and I might prefer it in the example shown where the arg name is fairly short. That said, man mv shows something like:

    mv [OPTION]... [-T] SOURCE DEST
    mv [OPTION]... SOURCE... DIRECTORY
    mv [OPTION]... -t DIRECTORY SOURCE...
    

    @brandtbucher
    Copy link
    Member

    For backward compatibility with 2 metavars, the two-name form should still be possible. Just pass metavar=("FOO", "FOO").

    @ericvsmith
    Copy link
    Member

    I don't think it's any more precise. It just seems verbose and confusing to me, while conveying the same information.

    [arg [arg ...]] to me means "optionally, an arg followed by one or more optional args".

    While [arg ...] to me means "optionally, one or more args".

    So, I'd vote for the simpler version, especially since we're presumably trying to communicate with people who aren't BNF or regex experts!

    @brandtbucher
    Copy link
    Member

    I went ahead and opened a PR, since it's been a month.

    @rhettinger
    Copy link
    Contributor

    New changeset a0ed99b by Raymond Hettinger (Brandt Bucher) in branch 'master':
    bpo-38438: Simplify argparse "star nargs" usage. (GH-17106)
    a0ed99b

    @rhettinger
    Copy link
    Contributor

    Bob, thanks for the suggestion.

    Brandt, thanks for the PR.

    @rhettinger rhettinger removed 3.7 (EOL) end of life 3.8 only security fixes labels Nov 12, 2019
    @ezio-melotti ezio-melotti transferred this issue from another repository Apr 10, 2022
    Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
    Labels
    3.9 only security fixes stdlib Python modules in the Lib dir type-bug An unexpected behavior, bug, or error
    Projects
    None yet
    Development

    No branches or pull requests

    3 participants