Linters & formatters

pycodestyle Error Codes Explained: E1 to E9 and W1 to W6

Linters & formatters · · Published 2026-10-27

Uniformed women telephone operators wearing headsets work side by side at a large switchboard
Women's Army Corps telephone operators at the switchboard during the Potsdam Conference, 1945. US National Archives, public domain.

Every warning from pycodestyle starts with a code such as E302 or W291. The same codes appear in flake8, which runs pycodestyle, and in ruff, which reimplements them. This page explains each family, with the fix for the codes you will meet most often.

Reading a warning

pycodestyle prints one line per problem: file, line, column, code and message.

optparse.py:69:11: E401 multiple imports on one line
optparse.py:77:1: E302 expected 2 blank lines, found 1

The tool's documentation is clear about its limits: it "does not enforce every single rule of PEP 8". Naming conventions and docstrings are out of its scope. In its default configuration it skips the checks listed above, "because they are not rules unanimously accepted, and PEP 8 does not enforce them". Passing --ignore replaces that default list rather than adding to it, a common surprise; flake8's --extend-ignore exists to add codes instead.

E1: indentation

CodeMeaning and fix
E101Indentation mixes tabs and spaces. Convert the file to spaces.
E111, E114Indentation is not a multiple of four (E114 for a comment line).
E112, E115Expected an indented block (after a line ending in a colon).
E113, E116Unexpected indentation.
E117Over-indented: more than one level at once.
E121 to E131Continuation lines: under- or over-indented, closing bracket misplaced, or a continuation that looks like the next logical line. E121, E123 and E126 are ignored by default.

See indentation and line length for the underlying rules.

E2: whitespace

CodeMeaning and fix
E201, E202Space just after an opening or before a closing bracket: f( x ) → f(x).
E203Space before a comma, semicolon or colon. Often disabled with black, which puts spaces around colons in complex slices as PEP 8 allows.
E211Space before the parenthesis of a call or the bracket of an index: f (x).
E221–E224Several spaces, or a tab, before or after an operator, often from aligning assignments.
E225Missing whitespace around an operator that needs it: x=1, if a==b.
E226–E228Missing whitespace around arithmetic (E226, ignored by default), bitwise or shift (E227) and modulo (E228) operators.
E231Missing whitespace after a comma, semicolon or colon: [1,2].
E241, E242Several spaces or a tab after a comma (ignored by default).
E251, E252Spaces around = in a keyword argument or plain default (E251), or missing around an annotated default (E252).
E261, E262Inline comment: fewer than two spaces before it, or not starting with # .
E265, E266Block comment not starting with # , or starting with ##.
E271–E275Several spaces or a tab around a keyword, or no space after one: if(x).

E3: blank lines

CodeMeaning and fix
E301Expected 1 blank line before a method.
E302Expected 2 blank lines before a top-level function or class.
E303Too many blank lines: more than two, or two inside a function or class.
E304Blank line between a decorator and its function.
E305Expected 2 blank lines after a function or class, before top-level code.
E306Expected 1 blank line before a nested definition.

E4: imports

E401: several modules imported on one line (import os, sys). E402: a module-level import that comes after other code. A docstring, comments, dunder assignments such as __all__ and conditional blocks are allowed before imports. Grouping and ordering imports is not checked by pycodestyle; tools such as isort or ruff handle it.

E5: line length

E501: line too long, with the length and the limit in the message, for example "(84 > 79 characters)". The limit is set with --max-line-length. Long URLs alone in a comment are tolerated, as is a long first line starting with #!. E502 flags a backslash that is redundant because the line is already inside brackets.

E7: statements

CodeMeaning and fix
E701, E702Several statements on one line, after a colon (if x: y()) or separated by semicolons.
E703Statement ends with a semicolon.
E704Function body on the same line as def (ignored by default).
E711, E712Comparison to None, True or False with == or !=. Use is, is not, or plain truthiness.
E713, E714not x in y and not x is y: write x not in y and x is not y.
E721Comparing types directly; use isinstance(), or is for exact type checks.
E722Bare except:; name the exception, or use except Exception:.
E731A lambda assigned to a name; use def.
E741–E743Ambiguous names l, O or I for a variable, class or function.

Most of these follow the programming recommendations at the end of PEP 8.

E9: runtime

E901: the file could not be tokenized, usually a syntax or indentation error. E902: the file could not be read. Fix these first: other checks stop when the tokenizer fails.

W1, W2, W3: indentation and whitespace warnings

W5: line breaks

W503 and W504 flag a line break before and after a binary operator. They contradict each other and both are ignored by default; PEP 8 suggests breaking before operators in new code. W505 limits the length of docstrings and comments when --max-doc-length is set.

W6: deprecation

W605: invalid escape sequence, such as "\d" in a regular expression written as a normal string. Python currently treats it as a backslash followed by the character, but emits a warning, and the documentation says it will eventually become an error. Use a raw string: r"\d+".

Selecting, ignoring and silencing

pycodestyle --select=E,W --max-line-length=88 src/
pycodestyle --ignore=E203,W503 src/
flake8 --extend-ignore=E203 src/

Configuration usually lives in setup.cfg or tox.ini under [pycodestyle], or [flake8] for flake8, which also reads a .flake8 file. For one line, add # noqa: E501; pycodestyle documents which of its checks honour noqa. Our guide to checking style locally shows complete configurations for pycodestyle, flake8 and ruff.

The checker on our home page implements most of the codes on this page in the browser, including all of E1 except the continuation-line checks, E2, E3, E4, E501, E7, W191, W291 to W293, W391 and W605.

Sources