Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Line Breaks on long class member names #3371

Closed
timozerrer opened this issue Nov 2, 2022 · 1 comment
Closed

Line Breaks on long class member names #3371

timozerrer opened this issue Nov 2, 2022 · 1 comment
Labels
F: linetoolong Black makes our lines too long T: bug Something isn't working

Comments

@timozerrer
Copy link

timozerrer commented Nov 2, 2022

Describe the bug

Black does not break lines containing class member access even though character line limit is exceeded.

To Reproduce

Given this code using dataclasses with long member names:

from dataclasses import dataclass


@dataclass
class SomeNestedDataclass:
    very_long_nested_dataclass_variable_name: str


@dataclass
class SomeDataclass:
    long_dataclass_variable_name: SomeNestedDataclass


def some_func(some_datclass_param):
    pass


some_dataclass = SomeDataclass(
    long_dataclass_variable_name=SomeNestedDataclass(
        very_long_nested_dataclass_variable_name="VeryLongString"
    )
)
some_func(
    some_datclass_param=some_dataclass.long_dataclass_variable_name.very_long_nested_dataclass_variable_name
)

Black removes line breaks if I insert them myself (See expected behaviour section).

Running black formatter with explicit line length:

 python3.8 -m black test_line_lenght.py --line-length 88                                                     
All done! ✨ 🍰 ✨
1 file left unchanged.

Pylint reports line exceeding length:

python3.8 -m pylint test_line_lenght.py --disable=missing-module-docstring,missing-function-docstring,unused-argument,missing-function-docstring,invalid-name,missing-class-docstring
************* Module test_line_lengh
test_line_lenght.py:24:0: C0301: Line too long (108/88) (line-too-long)

------------------------------------------------------------------
Your code has been rated at 8.89/10 (previous run: 8.89/10, +0.00)

Expected behavior

Black should insert line break on line exceeding 88 characters.
My interpretation it should look like this based on PEP8:

some_func(
    some_datclass_param=some_dataclass.long_dataclass_variable_name.
    very_long_nested_dataclass_variable_name
)

If manually applying this refactoring, black will revert so this assignment is a one-liner again.

Environment

  • Black's version: 22.10.0
  • OS and Python version:

Additional context
Similar issue on line breaks #1802 recommends using --experimental-string-processing which does not solve this issue.

I frequently use nested dataclasses in my projects and i run into this issue every now and then because pylint reports line-too-long errors.

@timozerrer timozerrer added the T: bug Something isn't working label Nov 2, 2022
@JelleZijlstra JelleZijlstra added the F: linetoolong Black makes our lines too long label Nov 2, 2022
@JelleZijlstra
Copy link
Collaborator

The last case is a duplicate of #510 (attribute chains). You mention various other cases, but those should get specific issues in the F: linetoolong Black makes our lines too long label.

@JelleZijlstra JelleZijlstra closed this as not planned Won't fix, can't repro, duplicate, stale Apr 29, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
F: linetoolong Black makes our lines too long T: bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants