安装
pip install mypy
配置
配置到PyCharm的External Tools
File → Settings → Tools → External Tools → +
Program:C:\Users\Administrators\AppData\Roaming\Python\Python36\Scripts\mypy.exe
Arguments:$FilePath$
Working directory:$FileDir$
PS:Arguments根据需求配置,查看官方文档
测试
from typing import List
def greeting(names: List[str]) -> str:
return 'Hello, {}'.format(', '.join(names))
print(greeting([1, 2, 3]))
Tools → External Tools → Mypy
结果
a.py:8: error: List item 0 has incompatible type "int"; expected "str"
a.py:8: error: List item 1 has incompatible type "int"; expected "str"
a.py:8: error: List item 2 has incompatible type "int"; expected "str"
Found 3 errors in 1 file (checked 1 source file)
安装插件mypy-pycharm
File → Settings → Plugins → 搜【mypy】 → Install → Restart
重启PyCharm后 → File → Settings → 设置Path to Pylint executable
C:\Users\Administrators\AppData\Roaming\Python\Python36\Scripts\mypy.exe
运行