psf / psf/black

Black should chop down long call chains which are not in an assignment

Open
#792 1 comment 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

F: linebreak T: style
Dominant language
Python
Stars
41.8k
Forks
2.9k
Avg merge
5d 6h
Merged PRs (30d)
9

Description

Black chops down long call chains which are assigned to a variable:


built = SomeBuilder().with_something("").with_something("").with_something("").with_something("").with_something("").with_something("").build()

is changed into




built = (
    SomeBuilder()
    .with_something("")
    .with_something("")
    .with_something("")
    .with_something("")
    .with_something("")
    .with_something("")
    .build()
)

However, the result is ugly and inconsistent if the result is not assigned to anything:

SomeBuilder().with_something("").with_something("").with_something("").with_something("").with_something("").with_something("").build()

is changed into





SomeBuilder().with_something("").with_something(
    ""
).with_something("").with_something("").with_something(
    ""
).with_something(
    ""
).build()

Operating system: Ubuntu 18.04
Python version: Python 3.6.7
Black version: black, version 18.9b0
Does also happen on master: Yes.

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 assigned and unassigned call-chain examples with the reported Black version, then trace the formatter entry point that handles long chained calls. Done means an unassigned chain is split consistently with the assigned example without regressing existing formatting behavior.

Written by the indexing model from the issue text.

Assessment

Tech stack
python
Domain
devtools
Issue type
Feature
Difficulty
4/5
Estimated time
3-5 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.