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

Dict with double string in value, the second string is align with key #2063

Closed
mathben opened this issue Mar 25, 2021 · 3 comments
Closed

Dict with double string in value, the second string is align with key #2063

mathben opened this issue Mar 25, 2021 · 3 comments
Labels
F: linebreak How should we split up lines? R: duplicate This issue or pull request already exists T: style What do we want Blackened code to look like?

Comments

@mathben
Copy link

mathben commented Mar 25, 2021

Describe the style change
Help to visualize long string in dictionary. To respect pep8, force double string, but the second string is align with the key and not the value.

Example in the current Black style

{
    "name": "Lorem ipsum dolor sit amet.",
    "description": "Lorem ipsum dolor sit amet. Lorem ipsum dolor sit amet. Lorem ipsum dolor sit amet. Lorem ipsum "
    "Lorem ipsum dolor sit amet. ",
}

Desired style

{
    "name": "Lorem ipsum dolor sit amet.",
    "description": "Lorem ipsum dolor sit amet. Lorem ipsum dolor sit amet. Lorem ipsum dolor sit amet. Lorem ipsum "
                   "Lorem ipsum dolor sit amet. ",
}

Additional context
black, version 20.8b1

black -l 100 -t py38 FILES
@mathben mathben added the T: style What do we want Blackened code to look like? label Mar 25, 2021
@sodul
Copy link

sodul commented Apr 13, 2021

We have a similar problem where dictionaries that had a value that would go over our line width so we put it on the next line which works well visually, but black changes it back and now we have lines that are too long.

We really do not like aligning the indents on the opening, since this is maintenance burden and all the lines need to be realigned if the key ever changes size. Black does pretty well at avoiding this trap.

For the given example this is how I believe Black should split:

{
    "name": "Lorem ipsum dolor sit amet.",
    "description":
        "Lorem ipsum dolor sit amet. Lorem ipsum dolor sit amet. Lorem ipsum dolor sit"
        " amet. Lorem ipsum Lorem ipsum dolor sit amet. ",
}

This would be consistent with the exisiting alignment style. I'm not sure why Black does not have a rule for that yet, or at least leave the existing key: value line split alone if it will go over the line width.

@sodul
Copy link

sodul commented Apr 22, 2021

This relates to #808, #847 and #620.

@JelleZijlstra
Copy link
Collaborator

Duplicate of #620

@JelleZijlstra JelleZijlstra marked this as a duplicate of #620 Jan 29, 2022
@ichard26 ichard26 added the R: duplicate This issue or pull request already exists label Jan 29, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
F: linebreak How should we split up lines? R: duplicate This issue or pull request already exists T: style What do we want Blackened code to look like?
Projects
None yet
Development

No branches or pull requests

4 participants