Skip to content

Potential inconsistency between Ruff's I and isort #2104

@AA-Turner

Description

@AA-Turner

I believe this is distinct from #1718; cross-linking in case there are similarities, though.

isort version: 5.11.4
Ruff version: 230

isort config:

[tool.isort]
line_length = 95
profile = "black"
remove_redundant_aliases = true

Commands:

(sphinx) PS I:\Development\sphinx> ruff -V        
ruff 0.0.230
(sphinx) PS I:\Development\sphinx> type bug.py                                   
from operator import add  # NoQA: F401
from operator import mul, sub
(sphinx) PS I:\Development\sphinx> ruff --isolated --select I bug.py
bug.py:1:1: I001 Import block is un-sorted or un-formatted
Found 1 error(s).
1 potentially fixable with the --fix option.
(sphinx) PS I:\Development\sphinx> isort --check bug.py 

Note Ruff wants to re-format to:

from operator import (
    add,  # NoQA: F401
    mul,
    sub,
)

whereas isort wants to reformat to:

from operator import add  # NoQA: F401
from operator import mul, sub

This appeared in the Sphinx project where some imports are type-comment only (e.g. in giving type annotations to iterators, where the pattern is for item in items: # type: blah`, should MyPy not be able to deduce the type of item``).

A

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