Black: Long key: value in a dictionary goes over line limit

Created on 9 May 2019  路  5Comments  路  Source: psf/black

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

Most helpful comment

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.

All 5 comments

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.

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

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

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

Dupe of #620

@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 https://github.com/psf/black/issues/620#issuecomment-481880006 and https://github.com/psf/black/issues/620#issuecomment-559415991).

Was this page helpful?
0 / 5 - 0 ratings