预提交:使用python 3.6.8运行flake8



我在系统上安装了Pyton 3.6.8。

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

我的承诺前配置文件是:

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

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

EDIT当我运行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键入导入(的作者,也是另一个(flake8(的维护者


TYP005代码来自flake8打字导入

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

--min-python-version 3.6.1

或在您的flake8配置中

[flake8]
min_python_version = 3.6.1

如果您正在分发库,您可以使用python_requires元数据指示支持的最低版本——这在setup.cfg中指定

[options]
python_requires >= 3.6.1

顺便说一句,我相信你的问题中缺少了一些信息,如果你的预提交配置中没有additional_dependenciesflake8将被隔离安装,并且无法访问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]

最新更新