Skip to content

Fix preview split for commented method chains#5218

Open
ishaanlabs-gg wants to merge 1 commit into
psf:mainfrom
ishaanlabs-gg:fix-method-chain-comment-split
Open

Fix preview split for commented method chains#5218
ishaanlabs-gg wants to merge 1 commit into
psf:mainfrom
ishaanlabs-gg:fix-method-chain-comment-split

Conversation

@ishaanlabs-gg

Copy link
Copy Markdown

Description

Fixes #3998.

When a standalone comment appears between chained method calls, Black could split the
same leading call differently depending on whether another chained call followed the
comment. This adds a preview-gated formatter feature so commented method chains split
the first trailer consistently.

The change is intentionally limited to dotted delimiter splitting when the line contains
a standalone comment. Stable style remains unchanged.

Checklist - did you ...

  • Implement any code style changes under the --preview style, following the stability policy?
  • Add an entry in CHANGES.md if necessary?
  • Add / update tests if necessary?
  • Add new / update outdated documentation?

Validation:

  • PYTHONPYCACHEPREFIX=.pycache-tmp /Volumes/STOREJET/2/Dependencies/black-3998-venv/bin/python -m pytest tests/test_format.py -k preview_method_chain_comment -q
  • PYTHONPYCACHEPREFIX=.pycache-tmp /Volumes/STOREJET/2/Dependencies/black-3998-venv/bin/python -m pytest tests/test_docs.py tests/test_schema.py -q
  • PYTHONPYCACHEPREFIX=.pycache-tmp /Volumes/STOREJET/2/Dependencies/black-3998-venv/bin/python -m pytest tests/test_format.py -q
  • git diff --check

@ishaanlabs-gg ishaanlabs-gg force-pushed the fix-method-chain-comment-split branch from cd5571e to e54ab69 Compare July 2, 2026 19:24
@cobaltt7

cobaltt7 commented Jul 3, 2026

Copy link
Copy Markdown
Collaborator

This is a design decision, so we need to discuss the pros and cons of both styles.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Inconsistent formatting of method call chain with comment

2 participants