dbr*_*dbr 48 python code-analysis
是否有类似于Pylint的内容,它将查看Python脚本(或运行它),并确定每行(或函数)需要哪个版本的Python?
例如,理论用法:
$ magic_tool <EOF
with something:
pass
EOF
1: 'with' statement requires Python 2.6 or greater
$ magic_tool <EOF
class Something:
@classmethod
def blah(cls):
pass
EOF
2: classmethod requires Python 2.2 or greater
$ magic_tool <EOF
print """Test
"""
EOF
1: Triple-quote requires Python 1.5 of later
Run Code Online (Sandbox Code Playgroud)
这样的事情可能吗?我想最简单的方法是在光盘上安装所有Python版本,运行每个版本的脚本,看看发生了什么错误.
Greg Hewgill 的工具 pyqver 有一段时间没有更新了。
vermin是一个类似的实用程序,它以详细模式 ( -vvv)显示决策中考虑的行。
% pip install vermin
% vermin -vvv somescript.py
Detecting python files..
Analyzing using 8 processes..
!2, 3.6 /path/to/somescript.py
L13: f-strings require 3.6+
L14: f-strings require 3.6+
L15: f-strings require 3.6+
L16: f-strings require 3.6+
print(expr) requires 2+ or 3+
Minimum required versions: 3.6
Incompatible versions: 2
Run Code Online (Sandbox Code Playgroud)
奖励:使用该参数,-t=V您可以定义V要与之兼容的目标版本。如果不满足此版本要求,脚本将以退出代码退出1,使其易于集成到测试套件中。