I'm editing a Django settings file that looks similar to the following:
# 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'
})
This setting lucy/settings/staging.py
, extends two other ones and I'd like to keep the 'star imports', so I'd like to ignore error codes E403
and E405
for this file.
However, the only way I see to do that is to add the #noqa: E403, E405
comment to every line that it applies; by writing # flake8: noqa
at the top of the file, it ignores all errors.
As far as I can tell from http://flake8.pycqa.org/en/3.1.1/user/ignoring-errors.html, it isn't possible to do this, or have I overlooked something?
There are two ways to ignore the file: By explicitly adding it to our list of excluded paths (see: flake8 --exclude ) By adding # flake8: noqa to the file.
[flake8] per-file-ignores = # line too long path/to/file.py: E501, This may be easier than using # noqa comments.
The convention of Flake8 is to assign a code to each error or warning, like the pep8 tool. These codes are used to configure the list of errors which are selected or ignored. Each code consists of an upper case ASCII letter followed by three digits.
An extension for flake8 that lets you configure (out-of-source) individual error codes to be ignored per file. This is mostly useful when dealing with legacy code, so that you don't have to ignore any existing error globally, but get the benefits of all checks in new files, while you avoid introducing new kind of errors in existing files.
If we ever want to disable Flake8 respecting # noqa comments, we can refer to flake8 --disable-noqa. If we instead had more than one error that we wished to ignore, we could list all of the errors with commas separating them: Finally, if we have a particularly bad line of code, we can ignore every error using simply # noqa with nothing after it.
It’s also possible as of Flake8 3.0 to combine usage of flake8 --select and flake8 --ignore. This chapter of the User Guide aims to educate about how Flake8 will report errors based on different inputs. By default, Flake8 has a list of error codes that it ignores.
This tells Flake8 to ignore any error codes starting with E1, E23 , or W503 while it is running. The documentation for flake8 --ignore shows examples for how to change the ignore list in the configuration file.
Starting with Flake8 3.7.0, you can ignore specific warnings for entire files using the --per-file-ignores
option.
Command-line usage:
flake8 --per-file-ignores='project/__init__.py:F401,F403 setup.py:E121'
This can also be specified in a config file:
[flake8]
per-file-ignores =
__init__.py: F401,F403
setup.py: E121
other/*: W9
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With