google / google/python-fire

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

未關閉
#33 4 則留言 4 個 reaction 已指派 0 人 在 GitHub 檢視
enhancement
主要語言
Python
星號
28.2k
分支
1.5k
PR 合併指標
30 天內沒有已合併 PR

描述

[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

貢獻指南

開啟貢獻指南

評估

這個 Issue 還沒有評估資料。

把新 issue 寄到你的電子郵件信箱

精選適合新手參與的 GitHub issue 摘要。