`argparse._SubParsersAction.add_parser` should default to `description` matching `help`
Nadie ha tomado este issue todavía.
- Lenguaje dominante
- Python
- Estrellas
- 77.2k
- Forks
- 35.9k
- Métricas de merge de PR
- Métricas de PR pendientes
Descripción
Feature or enhancement
Proposal:
import argparse
# create the top-level parser
parser = argparse.ArgumentParser(prog='PROG')
parser.add_argument('--foo', action='store_true', help='foo help')
subparsers = parser.add_subparsers(help='subcommand help')
# create the parser for the "a" command
parser_a = subparsers.add_parser('a', help='a help')
parser_a.add_argument('bar', type=int, help='bar help')
# create the parser for the "b" command
parser_b = subparsers.add_parser('b', help='b help', description='b help')
parser_b.add_argument('--baz', choices=('X', 'Y', 'Z'), help='baz help')
# parse the args
print(parser.parse_args())
This currently produces:
gsnedders@gsnedders-margot tmp.IKpGQE2mE3 % python3.13 test.py --help
usage: PROG [-h] [--foo] {a,b} ...
positional arguments:
{a,b} subcommand help
a a help
b b help
options:
-h, --help show this help message and exit
--foo foo help
gsnedders@gsnedders-margot tmp.IKpGQE2mE3 % python3.13 test.py a --help
usage: PROG a [-h] bar
positional arguments:
bar bar help
options:
-h, --help show this help message and exit
gsnedders@gsnedders-margot tmp.IKpGQE2mE3 % python3.13 test.py b --help
usage: PROG b [-h] [--baz {X,Y,Z}]
b help
options:
-h, --help show this help message and exit
--baz {X,Y,Z} baz help
It would be nicer, however, if add_parser's description parameter defaulted to the value of the help argument.
Has this already been discussed elsewhere?
This is a minor feature, which does not need previous discussion elsewhere
Links to previous discussion of this feature:
https://github.com/python/cpython/issues/89438 considered not outputting the value of help here to be a bug, but was closed because the description parameter also exists.
Linked PRs
- gh-135236
Guía de contribución
Primeros pasos
- Lee el issue completo y luego la guía de contribución del proyecto.
- Comenta en el issue que vas a ocuparte — evita que dos personas hagan lo mismo.
- Haz un fork del repositorio y trabaja en una rama.
- Abre un pull request que haga referencia al número del issue.
Línea de trabajo
Comienza en argparse._SubParsersAction.add_parser y revisa el PR vinculado gh-135236 para entender el comportamiento propuesto. Se considera terminado cuando un subparser usa su texto de ayuda como descripción predeterminada, mientras que una descripción proporcionada explícitamente sigue siendo efectiva, y el comportamiento relevante de argparse está cubierto por pruebas.
Escrito por el modelo de indexación a partir del texto del issue.
Evaluación
- Stack tecnológico
- python
- Área
- cli
- Tipo de issue
- Nueva funcionalidad
- Dificultad
- 2/5
- Tiempo estimado
- 1-3 horas
- Estado de actividad
- Estancado
- Claridad
- Bien especificado
- Aptitud para principiantes
- 25/100