google / google/python-fire

Should helputils._UsageStringFromFullArgSpec show PEP 484 Type Hints if Available?

Ouverte
#33 4 commentaires 4 réactions 0 personnes assignées Voir sur GitHub
enhancement
Langage dominant
Python
Étoiles
28.2k
Forks
1.5k
Métriques de merge des PR
Aucune PR mergée en 30 j

Description

[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

Guide de contribution

Ouvrir le guide de contribution

Évaluation

Cette issue n'a pas encore été évaluée.

Recevez les nouvelles issues par e-mail

Un résumé court des issues GitHub adaptées aux débutants.