Permalink
Cannot retrieve contributors at this time
Error / Violation Codes
Flake8 and its plugins assign a code to each message that we refer to as an
:term:`error code` (or :term:`violation`). Most plugins will list their error
codes in their documentation or README.
Flake8 installs pycodestyle
, pyflakes
, and mccabe
by default and
generates its own :term:`error code`s for pyflakes
:
Code | Example Message |
---|---|
F401 | module imported but unused |
F402 | import module from line N shadowed by loop variable |
F403 | ‘from module import *’ used; unable to detect undefined names |
F404 | future import(s) name after other statements |
F405 | name may be undefined, or defined from star imports: module |
F406 | ‘from module import *’ only allowed at module level |
F407 | an undefined __future__ feature name was imported |
F501 | invalid % format literal |
F502 | % format expected mapping but got sequence |
F503 | % format expected sequence but got mapping |
F504 | % format unused named arguments |
F505 | % format missing named arguments |
F506 | % format mixed positional and named arguments |
F507 | % format mismatch of placeholder and argument count |
F508 | % format with * specifier requires a sequence |
F509 | % format with unsupported format character |
F521 | .format(...) invalid format string |
F522 | .format(...) unused named arguments |
F523 | .format(...) unused positional arguments |
F524 | .format(...) missing argument |
F525 | .format(...) mixing automatic and manual numbering |
F541 | f-string without any placeholders |
F601 | dictionary key name repeated with different values |
F602 | dictionary key variable name repeated with different values |
F621 | too many expressions in an assignment with star-unpacking |
F622 | two or more starred expressions in an assignment (a, *b, *c = d) |
F631 | assertion test is a tuple, which is always True |
F632 | use ==/!= to compare str , bytes , and int literals |
F633 | use of >> is invalid with print function |
F634 | if test is a tuple, which is always True |
F701 | a break statement outside of a while or for loop |
F702 | a continue statement outside of a while or for loop |
F703 | a continue statement in a finally block in a loop |
F704 | a yield or yield from statement outside of a function |
F706 | a return statement outside of a function/method |
F707 | an except: block as not the last exception handler |
F721 | syntax error in doctest |
F722 | syntax error in forward annotation |
F723 | syntax error in type comment |
F811 | redefinition of unused name from line N |
F821 | undefined name name |
F822 | undefined name name in __all__ |
F823 | local variable name … referenced before assignment |
F831 | duplicate argument name in function definition |
F841 | local variable name is assigned to but never used |
F901 | raise NotImplemented should be raise NotImplementedError |
We also report one extra error: E999
. We report E999
when we fail to
compile a file into an Abstract Syntax Tree for the plugins that require it.
mccabe
only ever reports one :term:`violation` — C901
based on the
complexity value provided by the user.
Users should also reference pycodestyle’s list of error codes.
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
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?
asked Jun 19, 2018 at 0:04
Kurt PeekKurt Peek
49.1k83 gold badges282 silver badges499 bronze badges
4
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
answered Apr 17, 2019 at 15:07
Eugene YarmashEugene Yarmash
138k39 gold badges318 silver badges372 bronze badges
There is no way of specifying that in the file itself, as far as I’m concerned — but you can ignore these errors when triggering flake:
flake8 --ignore=E403,E405 lucy/settings/staging.py
answered Oct 26, 2018 at 14:37
Javier AriasJavier Arias
2,2192 gold badges14 silver badges26 bronze badges
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?
asked Jun 19, 2018 at 0:04
Kurt PeekKurt Peek
49.1k83 gold badges282 silver badges499 bronze badges
4
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
answered Apr 17, 2019 at 15:07
Eugene YarmashEugene Yarmash
138k39 gold badges318 silver badges372 bronze badges
There is no way of specifying that in the file itself, as far as I’m concerned — but you can ignore these errors when triggering flake:
flake8 --ignore=E403,E405 lucy/settings/staging.py
answered Oct 26, 2018 at 14:37
Javier AriasJavier Arias
2,2192 gold badges14 silver badges26 bronze badges
The Ignoring Errors docs currently list a way of ignoring a particular error for a particular line:
example = lambda: 'example' # noqa: E731
… and a way of ignoring all errors for an entire file:
# flake8: noqa
from foo import unused
function_that_doesnt_exist()
x = 1+ 2
… 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 __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?
asked Jan 8, 2018 at 16:02
Mark AmeryMark Amery
137k78 gold badges401 silver badges450 bronze badges
3
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».
answered Jan 31, 2019 at 6:15
Ross MacArthurRoss MacArthur
4,2451 gold badge20 silver badges35 bronze badges
1
Before version 3.7.0, ignoring specific errors was only implemented per-line but not per-file.
The feature was discussed in issue #324 and the project chose not to implement. An implementation was proposed in this merge request, which nobody has followed up on.
However, some extensions have emerged to address the problem:
-
[discontinued]
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.
bagerard
4,7672 gold badges25 silver badges44 bronze badges
answered Jan 8, 2018 at 16:41
ArminiusArminius
2,17818 silver badges21 bronze badges
1
I implemented a flake8 plugin flake8-in-file-ignores
to allow adding «ignore» rules in the file itself (as opposed to the built-in config approach), the plugin uses the following syntax
# flake8-in-file-ignores: noqa: E731,E123
answered Jan 27 at 11:02
bagerardbagerard
4,7672 gold badges25 silver badges44 bronze badges
Update .flake8
file with
ignore = E123,E125,H404,H405,H803 ... any other rools
answered Aug 10, 2022 at 16:55
JeksonJekson
2,6346 gold badges35 silver badges71 bronze badges
1
.. —— coding: utf-8 ——
.. image:: https://github.com/gforcada/flake8-isort/actions/workflows/testing.yml/badge.svg?branch=master
:target: https://github.com/gforcada/flake8-isort/actions/workflows/testing.yml
.. image:: https://coveralls.io/repos/gforcada/flake8-isort/badge.svg?branch=master
:target: https://coveralls.io/github/gforcada/flake8-isort?branch=master
Use isort
_ to check if the imports on your python files are sorted the way you expect.
Add an .isort.cfg
to define how you want your imports sorted and run flake8 as you usually do.
See isort documentation
_ for .isort.cfg
available options.
Install
Install with pip::
$ pip install flake8-isort
Install with conda::
$ conda install -c conda-forge flake8-isort
Configuration
If using the select
option from flake8
_ be sure to enable the I
category as well, see below for the specific error codes reported by flake8-isort
.
See flake8 --help
for available flake8-isort options.
Error codes
+————+————————————————————+
| Error code | Description |
+============+===========================================================+
| I001 | isort found an import in the wrong position |
+————+————————————————————+
| I002 | no configuration found (.isort.cfg or [isort] in configs) |
+————+————————————————————+
| I003 | isort expected 1 blank line in imports, found 0 |
+————+————————————————————+
| I004 | isort found an unexpected blank line in imports |
+————+————————————————————+
| I005 | isort found an unexpected missing import |
+————+————————————————————+
Requirements
- Python 3.7, 3.8, 3.9, 3.10, 3.11 and pypy3
- flake8
- isort
Relation to flake8-import-order
As an alternative to this flake8 plugin, there’s flake8-import-order
_ that could be worth checking out. In contrast to this plugin that defers all logic to isort, the flake8-import-order comes bundled with it’s own logic.
flake8-import-order comes with a few predefined set of styles meanwhile this plugin can be customized a bit more. But the biggest difference could lie in that flake8-isort actually has the corresponding sorting engine isort that can sort the import orders of your existing python files. Meanwhile flake8-import-order has no such corresponding tool, hence big existing projects who want to adopt either would get a more automized experience choosing flake8-isort.
License
GPL 2.0
.. isort
: https://pypi.python.org/pypi/isort
.. isort documentation
: https://pycqa.github.io/isort/docs/configuration/options.html
.. flake8-import-order
: https://pypi.python.org/pypi/flake8-import-order
.. option from flake8
: http://flake8.pycqa.org/en/latest/user/options.html#cmdoption-flake8-select
.. —— coding: utf-8 ——
Changelog
6.0.0 (2022-12-22)
-
Drop isort 4.x support.
[gforcada] -
Add support for flake8 6.0.0.
[gforcada] -
Add
--isort-no-skip-gitignore
option to allow temporarily overriding the set
value of isort’sskip_gitignore
option withFalse
. This can cause
flake8-isort to run significantly faster at the cost of making flake8-isort’s
behavior differ slightly from the behavior ofisort --check
. [gschaffner]
5.0.3 (2022-11-20)
- Fix broken
add_options
method, again. [casperdcl]
5.0.2 (2022-11-19)
- Fix broken
add_options
method [casperdcl]
5.0.1 (2022-11-18)
-
Improve the config option is added and read back. [gforcada]
-
Bump plugin version. [gforcada]
5.0.0 (2022-10-08)
-
Update dependencies. [gforcada]
-
Revamp GitHub actions. [gforcada]
-
Drop python 3.6, and add python 3.10. [gforcada]
-
Use linters and formatters to keep code sane and beautiful. [gforcada]
4.2.0 (2022-08-04)
- Fix compatibility with flake8 version 5. [nhymxu]
4.1.2.post0 (2022-07-25)
- Release it as a wheel as well. [gforcada]
4.1.2 (2022-07-25)
- The package no longer depends on
testfixtures
.
4.1.1 (2021-10-14)
- Release py3 only wheels..
4.1.0 (2021-10-14)
-
Support flake8 4.x [g-as]
-
Switch from travis-ci to github actions. [g-as]
-
Drop python 2.7 support and 3.5 as well [g-as]
4.0.0 (2020-08-11)
- Nothing changed yet.
4.0.0a0 (2020-08-07)
- support isort >= 5 [bnavigator, pkolbus]
3.0.1 (2020-07-08)
- Work around
FailedToLoadPlugin
exception by requiringisort
4.x. Likewise,
pin the major version of all dependencies, to reduce risk of any future
incompatibilities.
[pkolbus]
3.0.0 (2020-04-15)
- Let
isort
search the configuration, rather thanflake8-isort
try to find it.
[jnns]
2.9.1 (2020-03-28)
- Fix flake8 warning.
[sobolevn]
2.9.0 (2020-03-16)
- Add
python3.8
support.
[sobolevn]
2.8.0 (2019-12-05)
-
Look for isort configuration on
.flake8
files as well.
[JohnHBrock] -
Document how to install
flake8-isort
on conda.
[marcelotrevisani] -
Look for isort configuration on
pyproject.toml
files as well.
[sanjioh]
2.7.0 (2019-03-19)
-
Improve the README.
[barbossa] -
Fix isort output when pipes are used.
[maerteijn]
2.6.0 (2018-12-01)
-
Use pytest to run tests.
[gforcada] -
New error code I005 isort foundan unexpected missing import.
[charettes] -
Add
isort_show_traceback
option to show verbose multi-line output
fromisort
, turned off by default
[sobolevn]
2.5 (2018-03-15)
- Now requires isort >= 4.3.0.
[jleclanche]
2.4 (2018-02-25)
-
Fix input handling with flake8’s —stdin-display-name, and simplify it.
[blueyed] -
Remove flake8-polyfill dependency. flake8 >= 3.2.1 is required already, and
stdin is not read directly anymore.
[blueyed]
2.3 (2017-12-22)
-
Fix typo.
[paltman] -
Add tox.ini and .editorconfig to config search.
[cas—] -
Make this plugin compatible with flake8 hook.
As the hook copies the files out of tree,
flake8-isort never finds the correct configuration.
[jaysonsantos]
2.2.2 (2017-08-19)
- Workaround for isort bug when skipping files.
[danpalmer]
2.2.1 (2017-05-12)
- Release as universal wheel.
[gforcada]
2.2 (2017-03-26)
-
Support flake8 git hook.
[sergio-alonso] -
Support python 3.6.
[gforcada] -
Search configuration on home folder.
[gforcada]
2.1.3 (2016-11-25)
- Fix yet another corner case.
[gforcada]
2.1.2 (2016-11-25)
- Fix another corner case: ignored files.
[cas—]
2.1.1 (2016-11-25)
- Fix corner cases of isort: newlines and grouped imports.
[cas—]
2.1.0 (2016-11-24)
- Show the exact line and kind of error,
rather than a generic message.
[cas—]
2.0.3 (2016-11-22)
- Update trove classifiers.
[gforcada]
2.0.2 (2016-11-22)
-
Add flake8 classifier.
[sigmavirus24] -
Require flake8 3.2.1.
flake8 series 3.1.x and 3.2.0 where not reporting flake8-isort errors.
[gforcada] -
Test on pypy and pypy3.
[gforcada] -
Fix tests and formatting.
[gforcada]
2.0.1 (2016-09-22)
- Fix standard input processing.
[carljm]
2.0 (2016-09-14)
-
Refactor code to handle flake8 version 3.
[danpalmer] -
Require flake8 version 3.0.
[gforcada]
1.3 (2016-06-20)
-
Make error messages clearer.
[do3cc] -
Use either pep8 or pycodestyle (new name for pep8).
[Maxim Novikov] -
Fix coveralls.
[gforcada]
1.2 (2016-03-05)
- Allow stdin processing, this way text editor can pass input to flake8.
[mjacksonw]
1.1.1 (2016-02-16)
-
Silence isort messages.
[gforcada] -
Improve wording.
[gforcada]
1.1 (2016-02-16)
- Check for isort configuration on setup.cfg as well.
[plumdog]
1.0 (2015-12-16)
- Check for an isort configuration file.
[gforcada]
0.2 (2015-09-14)
- Fix entry point.
[gforcada]
0.1.post0 (2015-09-13)
- Release wheels as well.
[gforcada]
0.1 (2015-09-13)
-
Initial release
[gforcada] -
Add all boilerplate files.
[gforcada] -
Create the flake8 plugin per se.
[gforcada]