Break long property chains
- Dominant language
- Rust
- Stars
- 49.6k
- Forks
- 2.4k
- Avg merge
- 2d 1h
- Merged PRs (30d)
- 445
Description
Given a code line like the following, Ruff and Black both don't break the line, even it would be possible (and make it more readable IMHO). Black kinda tries to shorten the line a bit, but it would still be too long for the given limit.
This happens for example when extracting data from deeply object data structure.
```python
# Input:
foo = self.some_very.nested.data.which.is_really.really.deep_into_a_data_structure.far.beyond.line_length_limit
# Black 23.12.1:
foo = (
self.some_very.nested.data.which.is_really.really.deep_into_a_data_structure.far.beyond.line_length_limit
)
# Ruff 0.2.1
foo = self.some_very.nested.data.which.is_really.really.deep_into_a_data_structure.far.beyond.line_length_limit
```
What I would like to see is breaking the property chain into multiple lines, something like this:
```python
# Desired output:
foo = (
self
.some_very
.nested
.data
.which
.is_really
.really
.deep_into_a_data_structure
.far
.beyond
.line_length_limit
)
# Alternative desired output (less readable, but also less wasted lines)
foo = (
self.some_very.nested.data.which.is_really.really
.deep_into_a_data_structure.far.beyond
.line_length_limit
)
```
Note: This is closely related to #8598, thanks to [Micha in Discord](https://discord.com/channels/1039017663004942429/1207664692885983242/1207666684324880464) for the pointer.
Contributor guide
Research direction
Start by reviewing the issue's input, current Black and Ruff outputs, and the two proposed property-chain layouts; then compare the related discussion in #8598. Done means Ruff's formatter consistently breaks deeply chained properties into readable lines that respect the configured limit, with behavior matching an agreed output style.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- python, rust
- Domain
- tooling
- Issue type
- Feature
- Difficulty
- 5/5
- Estimated time
- Over a week
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100