black
black copied to clipboard
Line too long: Dictionary key-value pair
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?
Looks like black is failing to put parenthesis in there. Smells like a bug, thanks for reporting! May be related to #275 and #330
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.
Can confirm this still happens even with experimental string processing. Here's a playground for convenience.
Any update on a solution for this bug?
Any updates will be posted here!
@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?
@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 👍
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,
}