Skip to content

Different length sort behavior against isort #9870

@yanyongyu

Description

@yanyongyu

I'm trying to migrate isort and black to ruff but encountered some problems when using ruff's isort configs.

Ruff version 0.2.1.

Suppose I have a first-party package named package and the test code is:

from package.utils import a
from package.func import function

with the ruff config:

[tool.ruff.lint]
select = ["I"]

[tool.ruff.lint.isort]
length-sort = true
force-sort-within-sections = true

ruff will report import order error and fix it into:

from package.func import function
from package.utils import a

but isort sorts it as the origin test code given above.

I make one more test, renaming the package.func to package.function:

from package.utils import a
from package.function import function

this time ruff does not report any error. It seems ruff sort the import order by module name length instead of import expression length?

Metadata

Metadata

Assignees

No one assigned

    Labels

    isortRelated to import sortingneeds-decisionAwaiting a decision from a maintainer

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions