google / google/python-fire

Unhandled arguments checked after execution, not before

未關閉
#168 16 則留言 27 個 reaction 已指派 0 人 在 GitHub 檢視
主要語言
Python
星號
28.2k
分支
1.5k
PR 合併指標
30 天內沒有已合併 PR

描述

Consider a simple program:

```
import fire

def add(a, zero=0):
print('calculating...')
print(a + zero)

if __name__ == '__main__':
fire.Fire(add)
```

And then suppose we make a typo in the argument name, writing ``--zerro`` instead of ``--zero``. This is what I get with fire 0.1.3 under Python 3.6:

```
$ python t.py 1 --zerro 2
calculating...
1
Fire trace:
1. Initial component
2. Called routine "add" (t.py:3)
3. ('Could not consume arg:', '--zerro')

Type: NoneType
String form: None

Usage: t.py 1 -
```

Notice that first we run the code, and only then the error is reported. While I expected the errors to be checked before any user code is executed, because this code could be working for a long time, doing wrong things, etc.

貢獻指南

開啟貢獻指南

研究方向

首先,透過 fire.Fire(add) 進入點並使用拼寫錯誤的 --zerro 引數重現範例,然後追蹤相對於 add 執行而言引數在哪裡被消費。完成的標準是:在使用者程式碼執行之前回報無效引數,同時現有的錯誤行為仍然易於理解。

由索引模型根據 Issue 內容生成。

評估

技術堆疊
python
領域
cli
Issue 類型
缺陷
難度
4/5
預估耗時
3-5 天
活躍度
停滯
描述清晰度
描述清楚
新手友好度
42/100

把新 issue 寄到你的電子郵件信箱

精選適合新手參與的 GitHub issue 摘要。