PyCQA / PyCQA/isort

isort disagrees with black on wrapping over-long star imports

Open
#2,649 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
Python
Stars
7k
Forks
687
Avg merge
4h 56m
Merged PRs (30d)
2

Description

Description

Only over-long wildcard imports are affected. Under profile = black (line_length = 88), a from x import * under 88 chars is left alone; once it crosses 88, isort tries to wrap it. Parentheses are not an option, from x import (*) is a SyntaxError, and the dotted module path is the only over-long part, so isort falls back to a backslash continuation.

Black leaves such a line untouched (it also has no way to split it), so isort and black now fight over every long import * in a codebase.

Introduced by 65bfa80 ("Fix word-wrapping of 'from ... import *' into invalid Python (#2267)"), first shipped in 9.0.1. That commit fixed real corruption — thanks — but its message says star imports are "left on a single line", while the code in isort/wrap.py deliberately emits a backslash instead. PR #2559, which proposed returning the statement untouched to match black, was closed unmerged.

Steps to reproduce

# .isort.cfg
[settings]
profile = black
# 90 chars - isort rewrites this
from mypkg.vendor.hardware.sdk.bindings.generated.device_parameter_constants_v210 import *

# 88 chars - left alone, as expected
from mypkg.vendor.hardware.sdk.bindings.generated.device_parameter_constants_v2 import *

isort . gives:

from mypkg.vendor.hardware.sdk.bindings.generated.device_parameter_constants_v210 import \
    *

black . then rejoins it to one line. Running isort and black in either order does not converge.

Expected

Star imports left on a single line regardless of length under profile = black, matching black.

Notes

No setting avoids it: tested every multi_line_output (0-11), use_parentheses, wrap_length, balanced_wrapping, force_single_line, combine_star, split_on_trailing_comma. Only raising line_length above the line's length works, which then desyncs isort from black on ordinary long imports. multi_line_output = 7 (NOQA) keeps one line but appends # NOQA.

Reproduced on 9.0.1 and on main (Python 3.11).

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start in isort/wrap.py, where over-long from ... import * statements are wrapped, and inspect the existing behavior under profile = black. Reproduce the examples from the issue with isort and black; done means long star imports remain on one line and repeated runs of both tools converge without a backslash continuation.

Written by the indexing model from the issue text.

Assessment

Tech stack
python
Domain
tooling
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Active
Clarity
Clearly specified
Newbie friendliness
74/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.