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 too long: Dictionary key-value pair #413

Closed
ghost opened this issue Jul 19, 2018 · 8 comments
Closed

Line too long: Dictionary key-value pair #413

ghost opened this issue Jul 19, 2018 · 8 comments
Labels
F: linebreak How should we split up lines? F: linetoolong Black makes our lines too long F: parentheses Too many parentheses, not enough parentheses, and so on. T: bug Something isn't working

Comments

@ghost
Copy link

ghost commented Jul 19, 2018

Hey,

with black, version 18.6b4 I am getting two lines within dict merged resulting in line exceeding provided limit.

black --py36 --line-length 80 file

gives:

@ settings.py:153 @ REST_FRAMEWORK = {
    "DEFAULT_PERMISSION_CLASSES": (
        'some stuff here'
    ),
-    "DEFAULT_PAGINATION_CLASS":
-        "rest_framework.pagination.LimitOffsetPagination",
+    "DEFAULT_PAGINATION_CLASS": "rest_framework.pagination.LimitOffsetPagination",
    "PAGE_SIZE": some_value_here,
    "DEFAULT_FILTER_BACKENDS": (
        "django_filters.rest_framework.DjangoFilterBackend",

Line in question is 82 characters long.

Is that a bug or intended behaviour for dicts?

@zsol zsol added T: bug Something isn't working F: parentheses Too many parentheses, not enough parentheses, and so on. labels Jul 22, 2018
@zsol
Copy link
Collaborator

zsol commented Jul 22, 2018

Looks like black is failing to put parenthesis in there. Smells like a bug, thanks for reporting! May be related to #275 and #330

@ambv
Copy link
Collaborator

ambv commented Aug 17, 2018

In the mean time, if you put the value in parentheses manually, Black will keep them. We need to figure out a way to do it nicely automatically without over-extending.

@JelleZijlstra JelleZijlstra added the F: linetoolong Black makes our lines too long label May 30, 2021
@felix-hilden
Copy link
Collaborator

Can confirm this still happens even with experimental string processing. Here's a playground for convenience.

@berzi
Copy link

berzi commented May 10, 2022

Any update on a solution for this bug?

@felix-hilden
Copy link
Collaborator

Any updates will be posted here!

@govindrai
Copy link

govindrai commented May 18, 2022

@felix-hilden I am running into this as well. I haven't contributed to black before, but I am thinking to contribute. I have two questions: has this been prioritized? and is this a good candidate for a first contribution? It hasn't been resolved since 2018, could be due to complexity?

@felix-hilden
Copy link
Collaborator

felix-hilden commented May 18, 2022

@govindrai You're welcome to give it a go! It hasn't been prioritised, and could be a hard one (based on no real info though), but we'll try to help if you create a PR draft 👍

@JelleZijlstra
Copy link
Collaborator

This is fixed on main in preview mode:

% black -c '''REST_FRAMEWORK = {
    "DEFAULT_PERMISSION_CLASSES": (
        "some stuff here"
    ),
    "DEFAULT_PAGINATION_CLASS":
        "rest_framework.pagination.LimitOffsetPagination",
    "PAGE_SIZE": some_value_here,
}''' --preview -l 80
REST_FRAMEWORK = {
    "DEFAULT_PERMISSION_CLASSES": "some stuff here",
    "DEFAULT_PAGINATION_CLASS": (
        "rest_framework.pagination.LimitOffsetPagination"
    ),
    "PAGE_SIZE": some_value_here,
}

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? F: linetoolong Black makes our lines too long F: parentheses Too many parentheses, not enough parentheses, and so on. T: bug Something isn't working
Projects
None yet
Development

No branches or pull requests

6 participants