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

Long key: value in a dictionary goes over line limit #847

Closed
therve opened this issue May 9, 2019 · 5 comments
Closed

Long key: value in a dictionary goes over line limit #847

therve opened this issue May 9, 2019 · 5 comments

Comments

@therve
Copy link

therve commented May 9, 2019

If a dictionary has a key value which doesn't fit, black reformats it incorrectly. For example

a = {
    'averylongkeywhichdoesntfitin40charsxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx':
        'averylongvaluewhichwereallytostretch'
}

is reformatted to:

a = {'averylongkeywhichdoesntfitin40charsxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx': 'averylongvaluewhichwereallytostretch'}

I believe the first version is correct. The second one is certainly not. Possibly related to #808.

Operating system: OS X
Python version: 3.7.2
Black version: 19.3b0
Does also happen on master: yes

@bradyrx
Copy link

bradyrx commented Jun 2, 2019

I'm having the same issue here. This is problematic when black is combined with flake8 in CI, since black forces one line key:item pairs which forces it over the line limit.

@marcelotrevisani
Copy link

I am having the same problem, if the value is too long, black is not breaking it to new lines

@zsol zsol mentioned this issue Jul 26, 2019
@ljades
Copy link

ljades commented Jul 26, 2019

Did this issue ever get resolved? I'm running into it as well.

@zsol
Copy link
Collaborator

zsol commented Jul 30, 2019

I recently realized this is already reported. Let's move the conversation over there

Dupe of #620

@zsol zsol closed this as completed Jul 30, 2019
@Holt59
Copy link

Holt59 commented Nov 28, 2019

@zsol I've commented on #620, but this looks like two separate issues (my issue is very close to @therve original issue).

#620 is about black splitting lines incorrectly and making code harder to read. This issue is (in my opinion) much simpler than #620, it simply seems that given such code:

a = {
    key: value
}

...black does not split key: value even if the line is too long (see #620 (comment) and #620 (comment)).

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

No branches or pull requests

6 participants