PyCQA / PyCQA/pycodestyle

E131 applies inconsistently with nested calls

Open
#953 0 comments 0 reactions 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

I often use an indentation format like this for long method chains with something like SQLAlchemy, which seems to be acceptable according to my reading of PEP8 and doesn't raise any errors when pycodestyle is run:

rows = db.engine.execute(
    table.select()
         .where(table.c.column1 == 'something')
         .where(table.c.column2.is_(None))
         .order_by(table.c.column3)
         .limit(5)
)

However, if the name of the variable being assigned to is a particular length, E131 - continuation line unaligned for hanging indent is raised:

aaaaaaaa = db.engine.execute(
    table.select()
         .where(table.c.column1 == 'something')  # E131
         .where(table.c.column2.is_(None))       # E131
         .order_by(table.c.column3)              # E131
         .limit(5)                               # E131
)

It seems to be related to having the = operator aligned with the indented lines? Adding just a single character to the left side of the assignment will remove the E131.

aaaaaaaab = db.engine.execute(
    table.select()
         .where(table.c.column1 == 'something')
         .where(table.c.column2.is_(None))
         .order_by(table.c.column3)
         .limit(5)
)

Is this an issue in pycodestyle, or do I just not understand what's going on here?

$ pycodestyle --version
2.6.0

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

Start by reproducing the two assignment examples with pycodestyle 2.6.0 and compare the E131 results as the variable name changes. Trace the E131 check's handling of nested method calls and hanging indentation; done means equivalent valid formatting no longer changes behavior based on the assignment target's length, with regression coverage for the examples.

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
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.