Should helputils._UsageStringFromFullArgSpec show PEP 484 Type Hints if Available?
- Lingua principale
- Python
- Stelle
- 28.2k
- Fork
- 1.5k
- Metriche di merge delle PR
- Nessuna PR unita negli ultimi 30g
Descrizione
[PEP 484](https://www.python.org/dev/peps/pep-0484/) introduced the standard syntax for type annotations in Python. Consider this example
```python
import fire
def greeting(name:str, age:int) -> str:
return "{name} will be {new_age} in 1 year".format(name=name, new_age=age+1)
fire.Fire(greeting)
```
Python fire currently will show the following when I type `python test.py -- --help`
```
Type: function
String form:
File: c:\users\admin\desktop\test.py
Line: 4
Usage: test.py NAME AGE
test.py --name NAME --age AGE
```
Would it be helpful to give type hints here? Maybe something like this?
```
Usage: test.py NAME:str AGE:int
test.py --name NAME --age AGE
```
The implementation is very straightforward, I've already done it as a test on my local copy. We can use spec.annotations inside helputils._UsageStringFromFullArgSpec which gives a dict like this:
```python
{'name': , 'return': , 'age': }
```
Questions:
1. Are type hints useful here? Or are they just cluttering up the info?
2. Where should the type hints be? In both the usage lines? Just the first?
3. What should the syntax be? Should it be `var:type` or something else?
4. In the future could we use type hints to enhance parser.py.DefaultParseValue?
5. Show type hints for just the arguments or also for the return value of a function?
6. Support for Python 2 type hints? http://stackoverflow.com/questions/35230635/type-hinting-in-python-2
Guida per i contributori
Apri la guida per i contributori
Valutazione
Questa issue non è ancora stata valutata.