argparse option argument with `nargs=argparse.REMAINDER` is misplaced in usage line
Dieses Issue hat noch niemand übernommen.
- Vorherrschende Sprache
- Python
- Sterne
- 77.2k
- Forks
- 36k
- Ø Merge
- 1 T. 9 Std.
- Gemergte PRs (30 T.)
- 558
Beschreibung
Bug report
When using an optional argument with nargs=argparse.REMAINDER, the argument appears within the list of optional arguments and before any positional arguments. I expected it to be placed last in usage line, which would better match the behavior since it consumes any following parameters. Not sure it is really bug...
The following scripts shows the issue:
#!/usr/bin/env python
import argparse
parser = argparse.ArgumentParser()
parser.add_argument('foo')
parser.add_argument('--extra', nargs=argparse.REMAINDER)
parser.add_argument('--option')
args = parser.parse_args()
[--extra ...] is not at all last in the usage line:
$ ./test.py -h
usage: test.py [-h] [--extra ...] [--option OPTION] foo
positional arguments:
foo
options:
-h, --help show this help message and exit
--extra ...
--option OPTION
Your environment
- archlinux/amd64
- Tested on python 3.10.4 and also on 3.7.7 and 3.8.7.
Beitragsleitfaden
Erste Schritte
- Lies das ganze Issue und danach den Beitragsleitfaden des Projekts.
- Schreib ins Issue, dass du es übernimmst — das erspart doppelte Arbeit.
- Forke das Repository und arbeite in einem Branch.
- Öffne einen Pull Request, der die Issue-Nummer nennt.
Rechercherichtung
Führe das minimale argparse-Skript aus dem Bericht aus und untersuche, wie ArgumentParser seine Usage-Zeile für add_argument-Aufrufe mit nargs=argparse.REMAINDER formatiert. Bestätige die aktuelle Reihenfolge und ermittle die relevanten Tests oder den Einstiegspunkt für die Usage-Formatierung von argparse. Erledigt ist die Aufgabe, wenn die Remainder-Option in der Usage-Ausgabe nach den Positionsargumenten erscheint, ohne die Reihenfolge anderer Optionen zu verändern.
Vom Indexierungsmodell aus dem Issue-Text verfasst.
Bewertung
- Tech-Stack
- python
- Bereich
- cli
- Issue-Typ
- Bug
- Schwierigkeit
- 3/5
- Geschätzter Aufwand
- 1-2 Tage
- Aktivitätsstatus
- Veraltet
- Klarheit
- Größtenteils klar
- Anfängerfreundlichkeit
- 45/100