google / google/python-fire

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

オープン
#33 コメント 4 件 リアクション 4 件 担当者 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 を短くまとめたダイジェスト。