Skip to content

isort.combine-as-imports seems to act opposite to its definition #3528

@davfsa

Description

@davfsa

Hey!

I found what I believe is a little bug with regards to isorts combine-as-imports, as it seems to act contrary to its definition in some cases.

Sample reproduction code:

from json import detect_encoding
from json import dump
from json import dumps as json_dumps
from json import load
from json import loads as json_loads

Quite a bad example of "real world code", but there is a genuine use case behind this. The random imports are for the sake of showing the problem. Note that running isort with profile = "black" and force-single-line = true doesnt change this file

--fix while using combine-as-imports = true

$ ruff ruff_test.py --select I001 --fix
<no output>

$ cat ruff_test.py
from json import detect_encoding
from json import dump
from json import dumps as json_dumps
from json import load
from json import loads as json_loads

--fix while using combine-as-imports = false

$ ruff ruff_test.py --select I001 --fix
Found 1 error (1 fixed, 0 remaining).

$ cat ruff_test.py
from json import detect_encoding
from json import dump
from json import load
from json import dumps as json_dumps
from json import loads as json_loads

Ruff settings:

[tool.ruff]
line-length = 125
target-version = "py38"
select = ["E", "I", "F"]

[tool.ruff.isort]
force-single-line = true
combine-as-imports = true  # This line config will be added/removed according to the steps above

Ruff version:

ruff 0.0.255

Metadata

Metadata

Assignees

No one assigned

    Labels

    isortRelated to import sortingquestionAsking for support or clarification

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions