google / google/python-fire

Less than helpful help text for Optional[int] argument

オープン
#329 コメント 1 件 リアクション 4 件 担当者 0 名 GitHub で見る
主要言語
Python
スター
28.2k
フォーク
1.5k
PR マージ指標
30日以内にマージされた PR はありません

説明

Hi friends! Thanks as always for this _amazing_ library; it's really made building CLIs in Python a breeze.

One thing I've noticed recently: when `Fire`-ing a function with an argument of type `Optional[int]`, the help text for that argument has a bit of extraneous noise and gets cut off in such a way that we never see the `int` portion. Exempli gratia:

### Environment

```
~/tmp ∃ python3 -m venv env
~/tmp ∃ source env/bin/activate
(env) ~/tmp ∃ pip install -U -q pip fire
(env) ~/tmp ∃ python --version
Python 3.8.7
(env) ~/tmp ∃ pip freeze
fire==0.4.0
six==1.15.0
termcolor==1.1.0
```

### Script
```python
#!/usr/bin/env python
from typing import Optional
from fire import Fire

def main(n: Optional[int] = None):
n = 5 if n is None else n
print(f"You chose {n}.")

if __name__ == "__main__":
Fire(main)
```

### Running

When I run `./test.py --help`, I receive the following help message:

```
NAME
test.py

SYNOPSIS
test.py

FLAGS
--n=N
Type: Optional[typing.Unio...
Default: None
```

### Desiderata

Perhaps it's happening because [`Optional[T]` is equivalent to `Union[T, None]`](https://docs.python.org/3/library/typing.html#typing.Optional), but I find the type annotation's abbreviation`Optional[typing.Unio...]` in the help text a little wanting; ideally I'd prefer something like `Optional[int]` there. Granted, if this weren't a contrived, simplified example, I'd include a docstring that described the optional integer argument and not expect `fire` to take care of everything for me! But it'd be nice if we could see the type parameter inside that `Optional`.

Thanks again!

コントリビューションガイド

コントリビューションガイドを開く

評価

この issue はまだ評価されていません。

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

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