是否可以忽略Flake8中整个文件的某些错误代码?

问题描述 投票:4回答:2

我正在编辑一个类似于以下内容的Django设置文件:

# flake8: noqa
from lucy.settings.base import *
from lucy.settings.staging_production import *

# This ensures that errors from staging are tagged accordingly in Airbrake's console
AIRBRAKE.update(environment='staging')

LOGGING['handlers'].update(console={
    'class': 'logging.StreamHandler'
})

这个设置lucy/settings/staging.py,扩展了另外两个,我想保留'星级导入',所以我想忽略错误代码E403E405这个文件。

但是,我认为这样做的唯一方法是将#noqa: E403, E405注释添加到它应用的每一行;通过在文件顶部写入# flake8: noqa,它会忽略所有错误。

据我所知,http://flake8.pycqa.org/en/3.1.1/user/ignoring-errors.html,这是不可能的,或者我忽略了什么?

python pep8 flake8
2个回答
1
投票

从Flake8 3.7.0开始,您可以使用--per-file-ignores选项忽略整个文件的特定警告。

命令行用法:

flake8 --per-file-ignores='project/__init__.py:F401,F403 setup.py:E121'

这也可以在config file中指定:

[flake8]
per-file-ignores =
    __init__.py: F401,F403
    setup.py: E121
    other/*: W9

0
投票

就我而言,没有办法在文件本身中指定 - 但是你可以在触发片段时忽略这些错误:

flake8 --ignore=E403,E405 lucy/settings/staging.py
© www.soinside.com 2019 - 2024. All rights reserved.