Argparse: add method for retrieving the parsers of actions
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:
I have a CLI interface with an argparse.ArgumentParser composed of a bunch of different actions. I was trying to validate if an argument had been set to a default value, and with just the main parser available, I was having some issues using get_default() working from the main parser, rather than the parsers for the various actions.
I ended up going with the following comparison, in order to reduce the amount of refactoring I would need to do, where args is the var holding the object returned from parse_args():
args.my_param == parser._actions[1].choices[args.action]].get_default(args.my_param)
I could also have solved this by adding a wrapper class holding all the subparsers in an object of some kind.
But - I think it would be nice to have a public method for accessing these action parsers, mostly for enabling this kind of use case.
Has this already been discussed elsewhere?
Not that I could find
Links to previous discussion of this feature:
No response
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 con argparse.ArgumentParser, la colección _actions del parser, las opciones de los subparser y get_default(). Determina el alcance y el comportamiento previstos del método público para recuperar action parsers, incluido cómo debe admitir el caso de uso de validación de valores predeterminados descrito. Se considerará terminado cuando la API y su comportamiento estén claramente definidos y el feature esté cubierto por las pruebas adecuadas.
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
- 4/5
- Tiempo estimado
- 3-5 días
- Estado de actividad
- Estancado
- Claridad
- Bastante claro
- Aptitud para principiantes
- 35/100