Argparse: add method for retrieving the parsers of actions
Nessuno ha ancora preso questa issue.
- Lingua principale
- Python
- Stelle
- 77.2k
- Fork
- 35.9k
- Metriche di merge delle PR
- Metriche PR in attesa
Descrizione
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
Guida per i contributori
Apri la guida per i contributori
Come iniziare
- Leggi tutta la issue e poi la guida ai contributi del progetto.
- Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
- Fai un fork del repository e lavora su un branch.
- Apri una pull request che faccia riferimento al numero della issue.
Direzione di ricerca
Inizia con argparse.ArgumentParser, la raccolta _actions del parser, le scelte dei subparser e get_default(). Determina l'ambito e il comportamento previsti del metodo pubblico per recuperare gli action parser, incluso il modo in cui deve supportare il caso d'uso descritto per la convalida dei valori predefiniti. Il lavoro è completato quando l'API e il suo comportamento sono chiaramente definiti e la feature è coperta da test appropriati.
Scritto dal modello di indicizzazione a partire dal testo della issue.
Valutazione
- Stack tecnologico
- python
- Ambito
- cli
- Tipo di issue
- Funzionalità
- Difficoltà
- 4/5
- Tempo stimato
- 3-5 giorni
- Stato di attività
- Ferma
- Chiarezza
- Abbastanza chiara
- Idoneità per principianti
- 35/100