This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

classification
Title: argparse "usage" overly-complex with nargs="*"
Type: behavior Stage: resolved
Components: Library (Lib) Versions: Python 3.9
process
Status: closed Resolution: fixed
Dependencies: Superseder:
Assigned To: rhettinger Nosy List: bobjalex, brandtbucher, callumquick, eric.smith, nicktimko, paul.j3, rhettinger
Priority: normal Keywords: patch

Created on 2019-10-10 20:24 by bobjalex, last changed 2022-04-11 14:59 by admin. This issue is now closed.

Pull Requests
URL Status Linked Edit
PR 17106 merged brandtbucher, 2019-11-11 06:14
Messages (11)
msg354402 - (view) Author: Bob Alexander (bobjalex) * Date: 2019-10-10 20:24
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??
msg354410 - (view) Author: Eric V. Smith (eric.smith) * (Python committer) Date: 2019-10-10 21:55
I think [arg ...] would make sense.

Removing 3.5 and 3.6, since they're in security only mode. Adding 3.9.
msg354419 - (view) Author: Raymond Hettinger (rhettinger) * (Python committer) Date: 2019-10-11 05:19
Bob, would like to create a PR?
msg354450 - (view) Author: Brandt Bucher (brandtbucher) * (Python committer) Date: 2019-10-11 13:36
I’m happy to write one. This seems like a pretty straightforward fix.
msg354457 - (view) Author: Raymond Hettinger (rhettinger) * (Python committer) Date: 2019-10-11 14:18
Bob, as OP you get first dibs on a PR.
Brandt, you're next in line :-)
msg354467 - (view) Author: Nick Timkovich (nicktimko) * Date: 2019-10-11 17:02
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...
msg354475 - (view) Author: Brandt Bucher (brandtbucher) * (Python committer) Date: 2019-10-11 17:30
For backward compatibility with 2 metavars, the two-name form should still be possible. Just pass metavar=("FOO", "FOO").
msg354476 - (view) Author: Eric V. Smith (eric.smith) * (Python committer) Date: 2019-10-11 17:31
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!
msg356354 - (view) Author: Brandt Bucher (brandtbucher) * (Python committer) Date: 2019-11-11 06:16
I went ahead and opened a PR, since it's been a month.
msg356386 - (view) Author: Raymond Hettinger (rhettinger) * (Python committer) Date: 2019-11-11 20:47
New changeset a0ed99bca8475cbc82e9202aa354faba2a4620f4 by Raymond Hettinger (Brandt Bucher) in branch 'master':
bpo-38438: Simplify argparse "star nargs" usage. (GH-17106)
https://github.com/python/cpython/commit/a0ed99bca8475cbc82e9202aa354faba2a4620f4
msg356411 - (view) Author: Raymond Hettinger (rhettinger) * (Python committer) Date: 2019-11-12 05:09
Bob, thanks for the suggestion.

Brandt, thanks for the PR.
History
Date User Action Args
2022-04-11 14:59:21adminsetgithub: 82619
2019-11-12 05:09:42rhettingersetstatus: open -> closed
versions: - Python 3.7, Python 3.8
messages: + msg356411

resolution: fixed
stage: patch review -> resolved
2019-11-11 20:47:57rhettingersetmessages: + msg356386
2019-11-11 06:16:11brandtbuchersetmessages: + msg356354
2019-11-11 06:14:14brandtbuchersetkeywords: + patch
stage: patch review
pull_requests: + pull_request16612
2019-11-04 10:56:00callumquicksetnosy: + callumquick
2019-10-24 20:28:19paul.j3setnosy: + paul.j3
2019-10-11 17:31:45eric.smithsetmessages: + msg354476
2019-10-11 17:30:37brandtbuchersetmessages: + msg354475
2019-10-11 17:02:29nicktimkosetnosy: + nicktimko
messages: + msg354467
2019-10-11 14:18:33rhettingersetmessages: + msg354457
2019-10-11 13:36:50brandtbuchersetmessages: + msg354450
2019-10-11 05:19:43rhettingersetassignee: rhettinger
messages: + msg354419
2019-10-11 02:02:12xtreaksetnosy: + rhettinger
2019-10-11 00:06:40brandtbuchersetnosy: + brandtbucher
2019-10-10 21:55:33eric.smithsetnosy: + eric.smith

messages: + msg354410
versions: + Python 3.9, - Python 3.5, Python 3.6
2019-10-10 20:24:39bobjalexcreate