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

Wrapping imports is incompatible with isort #127

Closed
zen0wu opened this issue Apr 12, 2018 · 10 comments
Closed

Wrapping imports is incompatible with isort #127

zen0wu opened this issue Apr 12, 2018 · 10 comments
Labels
T: style What do we want Blackened code to look like?

Comments

@zen0wu
Copy link

zen0wu commented Apr 12, 2018

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,
)
@zen0wu
Copy link
Author

zen0wu commented Apr 12, 2018

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.

@carljm
Copy link
Collaborator

carljm commented Apr 12, 2018

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

@ambv
Copy link
Collaborator

ambv commented Apr 13, 2018

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.

@ambv ambv changed the title Imports with parentheses should be per-line with trailing comma Wrapping imports is incompatible with isort Apr 13, 2018
@ambv ambv added T: style What do we want Blackened code to look like? R: not a bug This is deliberate behavior of Black. labels Apr 13, 2018
@ambv
Copy link
Collaborator

ambv commented Apr 13, 2018

Reported on the isort end as PyCQA/isort#694.

@ambv ambv removed the R: not a bug This is deliberate behavior of Black. label Apr 24, 2018
@ambv
Copy link
Collaborator

ambv commented Apr 24, 2018

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.

@ambv ambv closed this as completed in 09f5ee3 Apr 24, 2018
Pierre-Sassoulas added a commit to Pierre-Sassoulas/generic-python-project that referenced this issue Nov 18, 2018
Pierre-Sassoulas added a commit to Pierre-Sassoulas/pylint that referenced this issue Mar 9, 2019
This is compatible with the current black configuration.
See : psf/black#127
Pierre-Sassoulas added a commit to Pierre-Sassoulas/pylint that referenced this issue Mar 9, 2019
This is compatible with the current black configuration.
See : psf/black#127
Pierre-Sassoulas added a commit to Pierre-Sassoulas/pylint that referenced this issue Mar 9, 2019
This is compatible with the current black configuration.
See : psf/black#127
Pierre-Sassoulas added a commit to Pierre-Sassoulas/pylint that referenced this issue Mar 19, 2019
This is compatible with the current black configuration.
See : psf/black#127
PCManticore pushed a commit to pylint-dev/pylint that referenced this issue Mar 20, 2019
This is compatible with the current black configuration.
See : psf/black#127
kimt33 added a commit to kimt33/repo-template that referenced this issue Jun 15, 2019
It seems that isort is not compatible with black at the moment:
psf/black#127
PyCQA/isort#694

Both isort and black are working on a solution, but at the moment, we'll use
flake8-import-order instead
kimt33 added a commit to kimt33/repo-template that referenced this issue Jun 16, 2019
It seems that isort is not compatible with black at the moment:
psf/black#127
PyCQA/isort#694

Both isort and black are working on a solution, but at the moment, we'll use
flake8-import-order instead
silviot added a commit to Abstract-Tech/derex.runner that referenced this issue Jun 25, 2019
It seems that isort is not compatible with black at the moment:
psf/black#127
PyCQA/isort#694

Both isort and black are working on a solution, but at the moment, we'll use
flake8-import-order instead
@monkut
Copy link

monkut commented Aug 13, 2019

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

@monkut
Copy link

monkut commented Aug 13, 2019

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

[settings]
multi_line_output=3
include_trailing_comma=True

@alexey-v-paramonov
Copy link

alexey-v-paramonov commented Jan 9, 2020

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

@BwL1289
Copy link

BwL1289 commented Jan 23, 2020

has anyone seen this issue pop up again?

@tardunge
Copy link

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

charliermarsh added a commit to astral-sh/ruff that referenced this issue Aug 15, 2023
## Summary

Unlike other statements, Black always adds a trailing comma if an
import-from statement breaks with a single import member. I believe this
is for compatibility with isort -- see
psf/black@09f5ee3,
psf/black#127, or
https://github.com/psf/black/blob/66648c528a95553c1f822ece394ac98784baee47/src/black/linegen.py#L1452
for the current version.

## Test Plan

`cargo test`, notice that a big chunk of the compatibility suite is
removed.

Before:

| project      | similarity index |
|--------------|------------------|
| cpython      | 0.75472          |
| django       | 0.99804          |
| transformers | 0.99618          |
| twine        | 0.99876          |
| typeshed     | 0.74233          |
| warehouse    | 0.99601          |
| zulip        | 0.99727          |

After:

| project      | similarity index |
|--------------|------------------|
| cpython      | 0.75472          |
| django       | 0.99804          |
| transformers | 0.99618          |
| twine        | 0.99876          |
| typeshed     | 0.74260          |
| warehouse    | 0.99601          |
| zulip        | 0.99727          |
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
T: style What do we want Blackened code to look like?
Projects
None yet
Development

No branches or pull requests

7 participants