Black: Wrapping imports is incompatible with isort

Created on 12 Apr 2018  路  10Comments  路  Source: psf/black

Howdy! Sorry you're having trouble. To expedite your experience,
provide some basics for me:

Operating system: Mac OS X 10.13.4
Python version: 3.6.5
Black version: 18.4a1
Does also happen on master: Yes

For example,

from django.http import HttpResponse, HttpResponseBadRequest, JsonResponse, HttpResponse, HttpRequest

would be formatted as

from django.http import (
    HttpResponse, HttpResponseBadRequest, JsonResponse, HttpResponse, HttpRequest
)

This is probably personal, but this looks a little bit weird. I would suggest this as a better formatting:

from django.http import (
    HttpRequest,
    HttpResponse,
    HttpResponseBadRequest,
    JsonResponse,
)
design

Most helpful comment

Added the following to the .isort.cfg resolved the issue:

[settings]
multi_line_output=3
include_trailing_comma=True

All 10 comments

To add a bit of context, I'm trying to make black work with isort. But it seems that black's formatting style is not among isort's list of multi-line output modes (https://github.com/timothycrosley/isort#multi-line-output-modes).

This creates a problem. When I save my python file, it's formatted with black, but isort (flake8-isort) would complain about incorrectly formatted imports, which basically put my code in a bad state.

This is also going to be a problem for Instagram adoption of Black.

This form of wrapping lines applies to all code in Black. Making an exception for imports alone is inconsistent, especially if motivated purely by another, optional tool for Black users.

I'm talking to @timothycrosley about introducing "multiline mode 8" in isort which would enable both tools to peacefully co-exist. I hope this works, if not, we'll think of other options.

Due to Timothy's silence on the isort end I decided to change how we're formatting imports to be compatible with his valuable tool.

hmmm.. hit this issue where black wants a comma, but isort does not...

Added the following to the .isort.cfg resolved the issue:

[settings]
multi_line_output=3
include_trailing_comma=True

I also had to add
line_length=88
to .isort.cfg cause isort has a max line length of 79 vs 88 in black

has anyone seen this issue pop up again?

im good with these.
[settings]
multi_line_output=3
include_trailing_comma=True
line_length=88

Was this page helpful?
0 / 5 - 0 ratings

Related issues

dgnsrekt picture dgnsrekt  路  3Comments

J0 picture J0  路  3Comments

madig picture madig  路  3Comments

brettcannon picture brettcannon  路  3Comments

dusty-phillips picture dusty-phillips  路  3Comments