String hinted arguments passed numerical values should not be coerced

オープン 初心者向け
#733 コメント 0 件 リアクション 0 件 担当者 0 名 GitHub で見る

まだ誰も着手していません。

評価

難易度
2/5
見積もり時間
1〜3時間
初心者へのやさしさ
70/100
issue の種類
バグ
明瞭さ
おおむね明確
活発さ
活発
技術スタック
python
領域
cli

調査の方向性

issue には tp.py の最小限の再現例がありますが、プロジェクトのファイルやテストは挙げられていません。まず Fire が CLI の値をどのように解析し、callable の引数に型ヒントを適用するかを追い、その後、string 型ヒント付き引数に関する該当テストを探してください。1.10 と '1.10' の両方が文字列として関数に渡され、この動作を網羅する回帰テストが追加されれば完了です。

索引モデルが issue の本文から書いたものです。

説明

Observed behavior

If a callable command function defines an argument with a string hint, e.g. arg: str, and a value of 1.10 is passed to it, then it receives an argument of type float with value 1.1 which has different meaning than the passed value.

This is particularly troublesome when dealing with versions since 1.1 is much different than 1.10.

Expected behavior

Fire should not coerce the value to a type different than the type hint, regardless of its format.

Reproduction

Code
# tp.py
import fire


def main(arg: str):
    print(f"Hello! {type(arg)} {arg}")


if __name__ == "__main__":
    fire.Fire(main)
Execution
$ python tp.py 1.10
Hello! <class 'float'> 1.1

or

$ python tp.py '1.10'
Hello! <class 'float'> 1.1

Metadata

fire version v0.7.1

主要言語
Python
スター
28.2k
フォーク
1.5k
PR マージ指標
30日以内にマージされた PR はありません

環境構築

はじめの一歩

  1. issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
  2. 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
  3. リポジトリをフォークし、ブランチを切って変更します。
  4. issue 番号を参照したプルリクエストを送ります。

google/python-fire のほかの issue

google/python-fire の issue をすべて見る

似ている issue

Python の issue をもっと見る

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。