Flake8:忽略整个文件的特定警告 [英] Flake8: Ignore specific warning for entire file
问题描述
忽略错误 文档当前列出了一种忽略特定行的特定错误的方法:
example = lambda: 'example' # noqa: E731
...以及忽略整个文件的 all 错误的方法:
# flake8: noqa
from foo import unused
function_that_doesnt_exist()
x = 1+ 2
...以及通过配置或通过命令行选项通过全局在整个项目中禁用特定错误的几种方式.
但是,如果我想忽略整个单个文件中的特定错误-例如,要禁用有关__init__.py
桶中未使用进口的警告,该怎么办?该文件仅导入了一堆类,以便其他包中的代码可以依次从中导入它们?文档似乎并未暗示任何语法.有可能吗?
从Flake8 3.7.0开始,您可以使用--per-file-ignores
选项执行此操作.
命令行示例
flake8 --per-file-ignores='project/__init__.py:F401 setup.py:E121'
或者在您的配置文件中
per-file-ignores =
project/__init__.py:F401
setup.py:E121
other_project/*:W9
在此处查看文档: The Ignoring Errors docs currently list a way of ignoring a particular error for a particular line: ... and a way of ignoring all errors for an entire file: ... and a couple of ways, either through config or through command-line options, of disabling a particular error globally across an entire project. But what if I want to ignore a particular error across the entirety of a single file - for instance, to disable warnings about unused imports in an As of Flake8 3.7.0 you can do this using the Command line example Or in your config file See the documentation here: http://flake8.pycqa.org/en/latest/user/options.html?highlight=per-file-ignores#cmdoption-flake8-per-file-ignores It is not possible to place a 这篇关于Flake8:忽略整个文件的特定警告的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!example = lambda: 'example' # noqa: E731
# flake8: noqa
from foo import unused
function_that_doesnt_exist()
x = 1+ 2
__init__.py
barrel file that just imports a bunch of classes so that code from other packages can import them from it in turn? The docs don't seem to hint at any syntax for this. Is it possible?--per-file-ignores
option.flake8 --per-file-ignores='project/__init__.py:F401 setup.py:E121'
per-file-ignores =
project/__init__.py:F401
setup.py:E121
other_project/*:W9
noqa
comment for specific codes at the top of a file like you can for individual lines. # flake8: noqa: F401
may at first appear to work, but it's actually being detected as only # flake8: noqa
, which means "ignore all messages in the file".