Skip to content

isort: bad interaction between force-sort-within-sections and force-to-top #3630

@bluetech

Description

@bluetech

Given this config:

[tool.isort]
force_to_top = ["typing"]
force_sort_within_sections = true

[tool.ruff]
select = ["I001"]
[tool.ruff.isort]
force-to-top = ["typing"]
force-sort-within-sections = true

and this isort-clean file:

from typing import Any
import abc
from abc import ABCMeta
import os

ruff fix gives:

import abc
import os
from typing import Any
from abc import ABCMeta

It looks like force-sort-within-sections (which says to not sort the imports and froms separately) is ignored. But if I comment out the force-to-top = ["typing"] setting, ruff gives:

import abc
from abc import ABCMeta
import os
from typing import Any

which is correct. So I'm guessing the two settings together cause the issue.

(I'll try to fix this issue when I get a chance, unless someone beats me to it)

Version: ruff 0.0.257

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't workingisortRelated to import sorting

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions