PyCQA / PyCQA/pycodestyle

E128: confusion with variable-length encoding (like UTF-8)

Open
#391 4 comments 1 reaction 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
Python
Stars
5.2k
Forks
754
PR merge metrics
No merged PRs in 30d

Description

E128 gets confused with variable-lenght (with multi-byte) encoding, such as UTF-8. Using a multi-byte character makes PEP8 return an E128 warning of under-indent. Tests show that it expects one more space for each multi-byte character, consistent with UTF-8 double-bytes for the extended I'm using.

Apparently PEP8 is either ignoring the shebang line or using len() directly with UTF-8 string without converting to unicode first (even with the 'u' prefix).

Example pep8utf8.py:

# -*- coding: utf-8 -*-
_EPSILON = {'pressao': {'psig': 1,
                        'kPag': 5},  # No error here
            'pressão': {'psig': 1,
                        'kPag': 5},  # Error
            }

Running pep8 --show-source pep8utf8.py yields:

pep8utf8.py:5:25: E128 continuation line under-indented for visual indent
                        'kPag': 5},  # Error
                        ^

Note 1: I have tried using unicode strings, but the error is still there.
Note 2: Python 2.7.6 |Anaconda 2.1.0 (32-bit)| (default, Nov 11 2013, 10:50:31) [MSC v.1500 32 bit (Intel)] on win32

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Reproduce the report with pep8utf8.py using pep8 --show-source pep8utf8.py, then trace the E128 visual-indent check and its handling of UTF-8 text. Done means equivalent dictionary indentation with a multibyte character no longer produces a false E128 warning.

Written by the indexing model from the issue text.

Assessment

Tech stack
python
Domain
tooling
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.