不能通过flake8-import-order而不触发I201和I202报错

2024-10-02 16:25:03 发布

您现在位置:Python中文网/ 问答频道 /正文

我目前正在为一个很酷的小python项目nameyPhotoCollage做贡献,维护者请求贡献者在考虑pull请求之前通过flake8检查(足够公平)。在

我的问题是我不能通过这些支票:在我的电脑上,没有抱怨。但在特拉维斯,我总是get the following errors

$ flake8 .
./photocollage/gtkgui.py:29:1: I202 Additional newline in a section of imports.
./photocollage/gtkgui.py:32:1: I202 Additional newline in a section of imports.
./photocollage/render.py:25:1: I202 Additional newline in a section of imports.

The command "flake8 ." exited with 1.

但是,我的代码如下所示:

gtkgui.py

^{pr2}$

我没有更改进口商品。以前的提交,所以我怀疑flake8-import-order发生了某种变化。有什么想法吗?在


Tags: of项目inpyflake8newline维护者section
1条回答
网友
1楼 · 发布于 2024-10-02 16:25:03

在你的计算机上获取这些错误

请尝试使用flake8flake8-import-order的最新版本:

pip3 install  user  upgrade flake8 flake8-import-order

另外,既然这是python3项目,那么您是否正在用python3运行flake8?根据您的操作系统,要运行的命令可以是:

^{pr2}$

或者

python3 -m flake8 .

关于这些新错误

你说得对:flake8-import-order最近似乎发生了变化,现在检测出假阳性。这是由于gi.repository设置导入版本的奇怪方式(gi.require_version()必须在导入之间调用)。在

我想除了禁用这些特定行上的flake8规则之外,您没有什么可以做的:

import gi
gi.require_version('Gtk', '3.0')  # noqa: E402
from gi.repository import Gtk, Gdk, GObject, GdkPixbuf  # noqa: I202

相关问题 更多 >