[bug] short flags/arguments does not work with `**kwargs`
まだ誰も着手していません。
評価
調査の方向性
issue にある2つの Python 例を実行し、kwargs の有無による短縮フラグの挙動を比較します。次に、短縮フラグとキーワード引数について、Python Fire の引数解析を追跡します。完了条件は、-f と -s が first_arg と second_arg に値を設定し、無関係なフラグが引き続き kwargs に現れること、そして両方のケースに対するリグレッションカバレッジがあることです。
索引モデルが issue の本文から書いたものです。
説明
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
- 主要言語
- Python
- スター
- 28.2k
- フォーク
- 1.5k
- PR マージ指標
- 30日以内にマージされた PR はありません
コントリビューションガイド
はじめの一歩
- issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
- 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
- リポジトリをフォークし、ブランチを切って変更します。
- issue 番号を参照したプルリクエストを送ります。
google/python-fire のほかの issue
-
難易度 2/5 1〜3時間 初心者へのやさしさ 85/100
google/python-fire#693 ·
-
Release 0.7.2? オープン
難易度 3/5 1〜2日 初心者へのやさしさ 38/100
google/python-fire#698 ·
-
難易度 3/5 1〜2日 初心者へのやさしさ 58/100
google/python-fire#672 · コメント 5 件 ·
-
難易度 4/5 3〜5日 初心者へのやさしさ 45/100
google/python-fire#665 · コメント 2 件 ·
-
難易度 4/5 3〜5日 初心者へのやさしさ 55/100
google/python-fire#659 · コメント 1 件 ·
google/python-fire の issue をすべて見る
似ている issue
-
Add: hunch オープン
難易度 2/5 1〜3時間 初心者へのやさしさ 74/100
AbdelStark/awesome-typesafe#104 ·
-
enhancement
難易度 2/5 1〜3時間 初心者へのやさしさ 72/100
-
難易度 2/5 1〜3時間 初心者へのやさしさ 68/100
DiamondLightSource/dodal#2211 ·
-
難易度 2/5 1〜3時間 初心者へのやさしさ 88/100
openml/openml-python#1749 ·
-
難易度 2/5 1〜3時間 初心者へのやさしさ 88/100
sipyourdrink-ltd/bernstein#6191 ·