[bug] short flags/arguments does not work with `**kwargs`
Nessuno ha ancora preso questa issue.
Valutazione
- Difficoltà
- 3/5
- Tempo stimato
- 1-2 giorni
- Idoneità per principianti
- 45/100
Direzione di ricerca
Esegui i due esempi Python dell'issue e confronta il comportamento delle opzioni brevi con e senza kwargs. Poi traccia l'analisi degli argomenti di Python Fire per le opzioni brevi e gli argomenti con nome. Il lavoro è completato quando -f e -s valorizzano first_arg e second_arg, mentre i flag non correlati continuano a comparire in kwargs, con copertura di regressione per entrambi i casi.
Scritto dal modello di indicizzazione a partire dal testo della issue.
Descrizione
Description:
Short flags/arguments (e.g. -u for --username) does not work with **kwargs
Example that works OK:
The following example works ok:
import fire
def cli(first_arg="left", second_arg="right"):
"""Prints the 2 arguments separated by bar
Parameters
----------
first_arg : str
the first arg
second_arg : str
the second arg
"""
print(f"{first_arg} | {second_arg}" )
if __name__ == '__main__':
fire.Fire(cli)
Help output
❯ python .\example.py -- --help
NAME
example.py - Prints the 2 arguments separated by bar
SYNOPSIS
example.py <flags>
DESCRIPTION
Prints the 2 arguments separated by bar
FLAGS
-f, --first_arg=FIRST_ARG
Default: 'left'
the first arg
-s, --second_arg=SECOND_ARG
Default: 'right'
the second arg
Usage with short flags
❯ python .\example.py -f="hello" -s="word"
hello | word
Example that does not work:
The following next example does not work with short flags, even when they are showing on the help output.
It is using **kwargs. It seems the short flags are going to the **kwargs dictionary.
import fire
def cli(first_arg="left", second_arg="right", **kwargs):
"""Prints the 2 arguments separated by bar
Parameters
----------
first_arg : str
the first arg
second_arg : str
the second arg
kwargs : str
additional args
"""
print(f"{first_arg} | {second_arg}" )
print(kwargs)
if __name__ == '__main__':
fire.Fire(cli)
Help output
❯ python .\example2.py -- --help
NAME
example2.py - Prints the 2 arguments separated by bar
SYNOPSIS
example2.py <flags>
DESCRIPTION
Prints the 2 arguments separated by bar
FLAGS
-f, --first_arg=FIRST_ARG
Default: 'left'
the first arg
-s, --second_arg=SECOND_ARG
Default: 'right'
the second arg
Additional flags are accepted.
additional args
Usage with short flags
❯ python .\example2.py -f="hello" -s="word"
left | right
{'f': 'hello', 's': 'word'}
In summary: the -f and -s arguments should be parsing to --first_arg and --second_arg but they are parsing to kwargs
- Lingua principale
- Python
- Stelle
- 28.2k
- Fork
- 1.5k
- Metriche di merge delle PR
- Nessuna PR unita negli ultimi 30g
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.
Altre issue di google/python-fire
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 85/100
google/python-fire#693 ·
-
Release 0.7.2? Aperta
Difficoltà 3/5 1-2 giorni Idoneità per principianti 38/100
google/python-fire#698 ·
-
Difficoltà 3/5 1-2 giorni Idoneità per principianti 58/100
google/python-fire#672 · 5 commenti ·
-
Difficoltà 4/5 3-5 giorni Idoneità per principianti 45/100
google/python-fire#665 · 2 commenti ·
-
Difficoltà 4/5 3-5 giorni Idoneità per principianti 55/100
google/python-fire#659 · 1 commento ·
Tutte le issue di google/python-fire
Issue simili
-
Add: hunch Aperta
Difficoltà 2/5 1-3 ore Idoneità per principianti 74/100
AbdelStark/awesome-typesafe#104 ·
-
enhancement
Difficoltà 2/5 1-3 ore Idoneità per principianti 72/100
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 68/100
DiamondLightSource/dodal#2211 ·
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 88/100
openml/openml-python#1749 ·
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 88/100
sipyourdrink-ltd/bernstein#6191 ·