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

时间:2018-06-19 00:04:23

标签: python pep8 flake8

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

Select * 
from table as tsv
left outer join 
    (select 
         p1.[Tenant Code],
         p1.[Trans Date],
         p1.[Payment Amount],
         p1.[Payment Type]
     from   
         HIS_vw_tenant_payments p1
     where  
         p1.R04_SQL_ID = (select max(p2.R04_SQL_ID)
                          from HIS_vw_tenant_payments p2
                          where p2.[Tenant Code] = p1.[Tenant Code]
                            and p2.[Account Code] = 'RENT'
                          group by [Tenant Code])
    ) as pt on tsv.[Tenant Code] = pt.[Tenant Code]

这个设置# 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.pyE403文件。

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

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

2 个答案:

答案 0 :(得分: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

答案 1 :(得分:0)

就我而言,无法在文件本身中指定该位置-但触发flake时您可以忽略这些错误:

flake8 --ignore=E403,E405 lucy/settings/staging.py