预提交:运行 flake8 和 python 3.6.8

pre-commit: run flake8 with python 3.6.8

我在我的系统上安装了 Pyton 3.6.8。

python3 --version   //-> Python 3.6.8
python3.6 --version //-> Python 3.6.8

我的预提交-config.yaml是:

repos:
-   repo: https://github.com/pre-commit/pre-commit-hooks
rev: v2.4.0
-   repo: https://gitlab.com/pycqa/flake8
rev: 3.7.9
hooks:
- id: flake8
  language_version: python3.6

我为我的项目安装了预提交挂钩。 每次当我想对 git 提交一些更改时,预提交是 运行 flake8 错误:

TYP005 NamedTuple does not support defaults in 3.6.0

这对于 Python 3.6.0 是正确的,因为此功能是在 Python 3.6.1+ 中引入并允许的。 https://docs.python.org/3.6/library/typing.html#typing.NamedTuple

如何使用 Python 3.6.8 将 flake8 配置为 运行?

编辑 当我 运行 flake8 file.rb 时,我没有收到错误消息 TYP005。

python3 -m pip install flake
flake --version //-> 3.7.9 (the same version as in the pre-commit script file)

免责声明:我是其中两个工具(预提交、flake8-typing-imports)的作者和另一个工具(flake8)的维护者


TYP005代码来自flake8-typing-imports

有两个选项可用于指示您对 flake8-typing-imports 的最低支持版本,第一个是命令行参数/flake8 设置:

--min-python-version 3.6.1

或者在你的 flake8 配置中

[flake8]
min_python_version = 3.6.1

如果您要分发一个库,您可以使用 python_requires metadata 指明支持的最低版本——这在 setup.cfg

中指定
[options]
python_requires >= 3.6.1

顺便说一句,我相信您的问题中缺少一些信息,如果您的预提交配置中没有 additional_dependenciesflake8 将被隔离安装并且无法访问诸如此类的插件as flake8-typing-imports——我猜你的配置实际上类似于:


-   repo: https://gitlab.com/pycqa/flake8
    rev: 3.7.9
    hooks:
    -   id: flake8
        additional_dependencies: [flake8-typing-imports==1.9.0]

当谈到上面的命令行参数时,您可以在此处将它们指定为 args(尽管我个人更喜欢配置文件方法)

    -   id: flake8
        args: [--min-python-version, '3.6.1']
        additional_dependencies: [flake8-typing-imports==1.9.0]