flake8
Flake8 Error Codes
Error and warning codes produced by Flake8, a Python style guide enforcement tool that wraps pycodestyle (PEP 8), Pyflakes (undefined names, unused imports), and McCabe complexity checks.
36 codes
references flake8.pycqa.org/en/latest/user/error-codes.htmlpycodestyle.pycqa.org/en/latest/intro.html
· All codes 36 codes
- C901 Function Is Too Complex The McCabe cyclomatic complexity of a function exceeds the configured threshold (default 10). Refactor the function into smaller pieces to reduce complexity.
- E101 Indentation Contains Mixed Spaces and Tabs A line's indentation mixes spaces and tabs. Python 3 forbids mixing indentation types; convert all indentation to spaces (preferred by PEP 8).
- E111 Indentation Is Not a Multiple of Expected Width A line's indentation level is not a multiple of the expected indentation width (default 4 spaces). Ensure consistent indentation.
- E117 Over-Indented A block is indented more than expected. The code is indented further than the current block's context requires.
- E201 Whitespace After Opening Bracket There is a space immediately after an opening parenthesis, bracket, or brace. PEP 8 recommends no space after '(', '[', or '{'.
- E202 Whitespace Before Closing Bracket There is a space immediately before a closing parenthesis, bracket, or brace. PEP 8 recommends no space before ')', ']', or '}'.
- E211 Whitespace Before '(' or '[' There is a space before a parenthesis or bracket when calling or indexing (e.g. func (args) or obj [idx]). Remove the space between the name and the bracket.
- E225 Missing Whitespace Around Operator An operator (arithmetic, comparison, assignment, etc.) is not surrounded by spaces. PEP 8 requires spaces around most operators for readability.
- E231 Missing Whitespace After Separator A comma, semicolon, or colon is not followed by a space (e.g. a,b instead of a, b). Add a space after the separator.
- E251 Unexpected Spaces Around Keyword / Parameter Equals There are spaces around the '=' sign in a keyword argument or default parameter value (e.g. def f(x = 1) or f(x = 1)). PEP 8 requires no spaces here.
- E261 At Least Two Spaces Before Inline Comment An inline comment (on the same line as code) does not have at least two spaces separating it from the code. PEP 8 requires at least two spaces before '#'.
- E262 Inline Comment Should Start With '# ' An inline comment does not start with '# ' (hash followed by a single space). Fix by ensuring the comment begins with exactly '# '.
- E265 Block Comment Should Start With '# ' A block comment (on its own line) does not start with '# '. Shebangs (#!) and coding declarations are exempt.
- E301 Expected 1 Blank Line Before Nested Definition A nested function or class definition is not preceded by a blank line. PEP 8 requires one blank line before a nested def or class.
- E302 Expected 2 Blank Lines A top-level function or class definition is not preceded by two blank lines. PEP 8 requires two blank lines before and after top-level definitions.
- E303 Too Many Blank Lines There are more consecutive blank lines than PEP 8 allows (2 between top-level definitions, 1 inside a function or class body).
- E305 Expected 2 Blank Lines After Definition Module-level code following a function or class definition is not separated by two blank lines.
- E401 Multiple Imports on One Line Multiple modules are imported in a single import statement (e.g. import os, sys). PEP 8 requires one import per line.
- E402 Module Level Import Not at Top of File An import statement appears after non-import code. PEP 8 requires all module-level imports to be at the top of the file, after docstrings and comments.
- E501 Line Too Long A line exceeds the maximum allowed length (79 characters by default, per PEP 8). Break the line or increase the configured max-line-length.
- E711 Comparison to None A value is compared to None using == or != instead of the identity operators 'is' or 'is not'. Use 'x is None' or 'x is not None'.
- E712 Comparison to True or False A value is compared to True or False using == or != rather than a truthiness check. Use 'if x:' or 'if not x:' instead of 'if x == True:'.
- E721 Do Not Compare Types, Use isinstance() Types are compared with == (e.g. type(x) == int) instead of using isinstance(). isinstance() is preferred as it supports subclass checks.
- E731 Do Not Assign a Lambda Expression A lambda expression is assigned directly to a variable (e.g. f = lambda x: x). Use a def statement instead for named functions.
- E741 Ambiguous Variable Name A variable, argument, or attribute is named 'l' (lowercase L), 'O' (uppercase O), or 'I' (uppercase i), which are easily confused with the digits 1 and 0.
- F401 Module Imported But Unused A module or name is imported but never referenced in the file. Remove the import or add it to __all__ if it is intentionally re-exported.
- F811 Redefinition of Unused Name From Import A name that was imported is redefined later in the same scope without being used. Either remove the import or use the imported name before redefining it.
- F821 Undefined Name A name is used that has not been defined in any accessible scope. Check for typos, missing imports, or use before assignment.
- F841 Local Variable Assigned But Never Used A local variable is assigned a value but is never read afterwards. Remove the assignment or use the value, or prefix the name with '_' to indicate it is intentionally unused.
- W191 Indentation Contains Tabs The file uses tab characters for indentation. PEP 8 recommends spaces; Python 3 disallows mixing tabs and spaces.
- W291 Trailing Whitespace A line ends with one or more trailing space characters. Remove trailing whitespace.
- W292 No Newline at End of File The file does not end with a newline character. POSIX tools and many editors expect files to end with a newline.
- W391 Blank Line at End of File The file ends with one or more blank lines. Remove the trailing blank lines so the file ends with exactly one newline after the last non-blank line.
- W503 Line Break Before Binary Operator A line break occurs before a binary operator. PEP 8 now recommends breaking before operators (W504 covers the opposite). W503 and W504 are mutually exclusive; choose one style consistently.
- W504 Line Break After Binary Operator A line break occurs after a binary operator rather than before the next operand. PEP 8 prefers breaking before the operator. W503 and W504 are mutually exclusive; choose one style consistently.
- W605 Invalid Escape Sequence A string contains a backslash escape sequence that is not a recognised Python escape (e.g. '\p'). Use a raw string (r'...') or double the backslash ('\\p') to fix.