静态检查python代码
py_static_check的Python项目详细描述
py_static_检查
py_static_check可以静态地检查python代码中的许多常见错误。 它使用了一个修改过的pyflakes代码,并扩展了以下内容:
- Ability to specify what star imports resolve to (-s argument)
- Ability to ignore unused import warnings (-i argument)
- Better sorting of warnings/errors
有关详细信息,请查看:
要安装它,请执行以下操作:
sudo easy_install py_static_check
下面是py_static_check可以做的一些事情。
捕获未定义的名称,即使对于星形导入也是如此
示例代码:
from os import * def function_with_error(): print path print paths
星光进口.py:
import os STAR_IMPORTS = { 'os': os.__all__, }
使用py_static_check运行时:
$ py_static_check -s tests/star_import.py tests/undefined_name_star.py tests/undefined_name.py:5: undefined name 'paths
忽略未使用的警告
检查代码:
from os import path
使用py_static_check-i选项运行时:
$ py_static_check -i tests/ignore_not_used.py $ py_static_check tests/ignore_not_used.py tests/ignore_not_used.py:10: 'path' imported but unused
已分配但从未使用
像pyflakes一样,它可以捕获很多错误,比如定义一个变量而不使用它。
检查代码:
def some_function(): def inner_fn(): local_var = ""
使用py_static_check运行时:
$ py_static_check tests/assigned_but_never_used.py tests/assigned_but_never_used.py:8: local variable 'local_var' is assigned to but never used
版权所有:AMIX 2011 执照:麻省理工学院。