python - 不提高 I201 和 I202 就无法通过 flake8-import-order

标签 python flake8

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

我的问题是我无法通过这些检查:在我的计算机上,没有投诉。但是在 Travis 上,我总是 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

# -*- coding: utf-8 -*-
# Copyright (C) 2013 Adrien Vergé
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License along
# with this program; if not, write to the Free Software Foundation, Inc.,
# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.

import copy
import gettext
from io import BytesIO
import math
import os.path
import random
import sys

import cairo
import gi
gi.require_version('Gtk', '3.0')  # noqa
from gi.repository import Gtk, Gdk, GObject, GdkPixbuf
from six.moves import urllib  # Python 2 backward compatibility

from photocollage import APP_NAME, artwork, collage, render
from photocollage.render import PIL_SUPPORTED_EXTS as EXTS


gettext.textdomain(APP_NAME)
_ = gettext.gettext
_n = gettext.ngettext

(...)

我没有更改进口 wrt。以前的提交,所以我怀疑 flake8-import-order 以某种方式改变了。有什么想法吗?

最佳答案

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

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

pip3 install --user --upgrade flake8 flake8-import-order

此外,由于这是 Python 3 项目,您是否使用 Python 3 运行 flake8?根据您的操作系统,运行的命令可能是:

flake8 .

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

关于python - 不提高 I201 和 I202 就无法通过 flake8-import-order,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47236080/

相关文章:

python - 字符(音节)在枕头中未按正确的顺序呈现

python - 如何使用 NLTK ne_chunk 提取 GPE(位置)?

python - 如何使用 Flake8 将 for 语句拆分为多行?

python - 每个项目 flake8 最大行长度?

python - flake8 在过滤器子句中提示 bool 比较 "=="

python - 从一串硬币抛掷中计算出少数反面的子串

python - 我应该尽量减少 Pony ORM 中 db_session 的使用吗? db_session 的目的是什么?

python - 在 Ipython 中使用 Pylint(Jupyter-Notebook)

python - 为什么 pep8/flake8 无法检测仅在 if 分支中声明的未绑定(bind)局部变量

c++ - 用于执行稀疏线性代数的应用程序的 Python 与 C++