Less than helpful help text for Optional[int] argument
- Langage dominant
- Python
- Étoiles
- 28.2k
- Forks
- 1.5k
- Métriques de merge des PR
- Aucune PR mergée en 30 j
Description
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!
Guide de contribution
Ouvrir le guide de contribution
Évaluation
Cette issue n'a pas encore été évaluée.