google / google/python-fire

Less than helpful help text for Optional[int] argument

Đang mở
#329 1 bình luận 4 reaction 0 người được giao Xem trên GitHub
Ngôn ngữ chính
Python
Star
28.2k
Fork
1.5k
Chỉ số merge pull request
Không có pull request nào được merge trong 30 ngày

Mô tả

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!

Hướng dẫn đóng góp

Mở hướng dẫn đóng góp

Đánh giá

Issue này chưa được đánh giá.

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.