Flake8: Ignore specific warning for entire file

吃可爱长大的小学妹 提交于 2019-12-03 09:22:30
Ross MacArthur

As of Flake8 3.7.0 you can do this using the --per-file-ignores option.

Command line example

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

Or in your config file

per-file-ignores =
    project/__init__.py:F401
    setup.py:E121
    other_project/*:W9

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 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".

Arminius

Before version 3.7.0, ignoring specific errors was only implemented per-line but not per-file.

The feature is being tracked and discussed in issue #89 from which only the per-line proposal has been adopted. More recently, an implementation has been proposed in this merge request, which nobody has followed up on.

However, some extensions have emerged to address the problem:

  • flake8-per-file-ignores lets you ignore specific warning/errors for specific files via an entry in the config.

  • flake8-putty claims to do the same, but hasn't been updated for a while.

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!