Should helputils._UsageStringFromFullArgSpec show PEP 484 Type Hints if Available?
- 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ả
[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
Hướng dẫn đóng góp
Đánh giá
Issue này chưa được đánh giá.