使用选项运行mypy以过滤错误并为输出着色
mypy-runner的Python项目详细描述
通过一次只关注一小部分问题来简化静态类型检查。
在现有的代码库中,即使在最宽松的设置下,也很难通过MyPy的检查,不幸的是,直到您不能使用MyPy作为CID/CD过程的一部分。mypy-runner允许您通过标识要检查的文件和错误的子集逐步引入类型检查:
- 选择一组要检查的文件和错误
- 让测试通过并在ci和预提交挂钩中强制它们
- 重复
功能
mypy-runner将以下功能添加到mypy:
- 显示彩色输出
- 将特定错误转换为警告
- 筛选特定的错误和警告
选项
usage: mypyrun [-h] [--list] [--daemon] [--select SELECT] [--ignore IGNORE] [--warn WARN] [--no-color] [--show-ignored] [--show-error-keys] [--options OPTIONS] [files [files ...]] positional arguments: files Files to isolate (triggers use of 'active'options for these files) optional arguments: -h, --help show this help message and exit --list list error codes --daemon, -d run in daemon mode (dmypy run) --select SELECT, -s SELECT Errors to check (comma separated) --ignore IGNORE, -i IGNORE Errors to skip (comma separated) --warn WARN, -w WARN Errors to convert into warnings (comma separated) --no-color do not colorize output --show-ignored, -x Show errors that have been ignored (darker if using color) --show-error-keys Show error key for each line --options OPTIONS, -o OPTIONS Override the default options to use the namedconfiguration section (e.g. pass --options=foo to use the [mypyrun-foo] section)
与flake8等工具一样,您可以使用特定的错误代码来启用或禁用错误输出。 忽略或转换为警告的错误不会触发非零退出状态。 要查看错误代码及其regex模式的列表,请运行mypyrun --list。
配置
mypyrun在mypy.ini或mypyrun.ini中查找[mypyrun]节。
下面是一个配置文件示例:
[mypyrun]# run dmypy instead of mypydaemon=true# only display these errorsselect= not_defined, return_expected, return_not_expected, incompatible_subclass_attr,# all other errors are warningswarn=*# filter errors generated from these paths:exclude= thirdparty/*,# pass these paths to mypypaths= arnold/python, houdini/python, katana/python, mari/python, maya/python, nuke/python, python/packages,