Error / Violation Codes

Flake8 and its plugins assign a code to each message that we refer to as an error code (or 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 error code s for pyflakes:

CodeExample Message
F401module imported but unused
F402import module from line N shadowed by loop variable
F403‘from module import *’ used; unable to detect undefined names
F404future import(s) name after other statements
F405name may be undefined, or defined from star imports: module
F406‘from module import *’ only allowed at module level
F407an undefined __future__ feature name was imported
F501invalid % 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
F541f-string without any placeholders
F601dictionary key name repeated with different values
F602dictionary key variable name repeated with different values
F621too many expressions in an assignment with star-unpacking
F622two or more starred expressions in an assignment (a, *b, *c = d)
F631assertion test is a tuple, which is always True
F632use ==/!= to compare str, bytes, and int literals
F633use of >> is invalid with print function
F634if test is a tuple, which is always True
F701a break statement outside of a while or for loop
F702a continue statement outside of a while or for loop
F704a yield or yield from statement outside of a function
F706a return statement outside of a function/method
F707an except: block as not the last exception handler
F721syntax error in doctest
F722syntax error in forward annotation
F723syntax error in type comment
F811redefinition of unused name from line N
F821undefined name name
F822undefined name name in __all__
F823local variable name … referenced before assignment
F824global name / nonlocal name is unused: name is never assigned in scope
F831duplicate argument name in function definition
F841local variable name is assigned to but never used
F901raise 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 violation - C901 based on the complexity value provided by the user.

Users should also reference pycodestyle’s list of error codes.