Python
PEP8
E128
Code Style
Indentation

What is PEP8's E128 continuation line under-indented for visual indent?

Master System Design with Codemia

Enhance your system design skills with over 120 practice problems, detailed solutions, and hands-on exercises.

Introduction

E128 is a style warning raised by tools such as pycodestyle and flake8 when a wrapped line is not indented deeply enough to look visually connected to the line above it. The warning is about readability, not Python syntax. Your code may run perfectly while still violating the visual indentation rule.

What a Continuation Line Is

A continuation line appears when one logical statement spans multiple physical lines. This usually happens inside parentheses, brackets, or braces, where Python allows implicit line continuation.

For example:

python
1result = some_function(
2    long_argument_name,
3    another_argument,
4    third_argument,
5)

Those indented lines are continuation lines. They continue the statement that started on the first line.

The linter is therefore judging the shape of the wrapped statement as a whole. It wants the reader to see immediately that the lower lines belong to the still-open expression above them.

If the indentation is too shallow, the wrapped code can look like a brand new block rather than a continuation of the current statement.

Why E128 Happens

E128 specifically means the continuation line is under-indented for the chosen visual indentation style. The formatter or linter expected the wrapped line to line up more clearly with the opening delimiter or with the intended hanging indent.

Problematic style:

python
1result = some_function(
2  long_argument_name,
3  another_argument,
4  third_argument,
5)

Preferred style:

python
1result = some_function(
2    long_argument_name,
3    another_argument,
4    third_argument,
5)

The second version makes the continuation visually obvious.

Visual Indent Versus Hanging Indent

PEP 8 allows a few acceptable wrapping styles, but whichever style you choose should be clear and consistent.

Visual alignment style:

python
total = my_function(first_argument, second_argument,
                    third_argument, fourth_argument)

Hanging indent style:

python
1total = my_function(
2    first_argument,
3    second_argument,
4    third_argument,
5    fourth_argument,
6)

Both can be acceptable. E128 appears when the wrapped line does not meet the indentation expectations for the chosen style.

A Common Real Example

The warning often appears in boolean conditions or long function calls.

Bad:

python
1if (user.is_active and
2  user.is_verified and
3  user.has_subscription):
4    print("allowed")

Better:

python
1if (
2    user.is_active
3    and user.is_verified
4    and user.has_subscription
5):
6    print("allowed")

This version is easier to scan, and it avoids arguing about exactly how much horizontal alignment should be used.

Let Formatters Solve It

The easiest way to avoid E128 entirely is to use an automatic formatter such as black. A formatter applies one consistent style across the project and removes most indentation debates.

You can also use autopep8 for smaller PEP 8 cleanup passes:

bash
autopep8 --in-place example.py
flake8 example.py

The combination is useful because the formatter rewrites the line and the linter confirms the warning is gone.

Common Pitfalls

The biggest mistake is assuming E128 means the code is syntactically invalid. It usually is not. The problem is visual structure, not parser correctness.

Another issue is mixing visual alignment and hanging indent styles in the same expression. Either style can work, but mixing them often confuses linters and human readers alike.

People also sometimes fix the warning by adding arbitrary spaces until the linter stops complaining, without making the code more readable. The better fix is usually to rewrite the statement into a cleaner multiline shape.

Finally, do not fight the formatter if your team uses one. The value of PEP 8 tooling comes mostly from consistency across files, not from defending one person's preferred spacing pattern.

Summary

  • 'E128 means a continuation line is not indented clearly enough for visual readability.'
  • The warning concerns style, not Python execution semantics.
  • Use either a clean visual alignment or a clean hanging indent.
  • Multiline conditions and function calls are the most common places to trigger it.
  • Automatic formatters are the easiest long-term way to avoid E128.

Course illustration
Course illustration

All Rights Reserved.