Pau*_*ter 8 python static-typing python-2.7 mypy
新版本应该支持2.7,但是pip安装它失败了,并且在一行中使用了python 3类型注释语法的SyntaxError(这有点讽刺):
Traceback (most recent call last):
...
from mypy import git
File "mypy/git.py", line 10
def is_git_repo(dir: str) -> bool:
^
SyntaxError: invalid syntax
Run Code Online (Sandbox Code Playgroud)
你不能在Python 2上运行Mypy.项目的README是特定的:
您需要Python 3.2或更高版本才能运行mypy.
您仍然可以在Python 2代码上使用它.只需使用基于注释的注释,并给Mypy --py2标志.您还需要Python 2的输入库,您可以使用pip进行安装:
pip install typing
Run Code Online (Sandbox Code Playgroud)