Skip to content

Removing import resorts imports in a way incompatible with isort #229

@jakkdl

Description

@jakkdl

isort sorts ALL_CAPS objects before other objects, while autoflake sorts purely lexically after removing an unused import object from a from ... import ... line - which causes discrepancies and means isort has to be run after autoflake in CI's.

Example:

initial file

from typing import TYPE_CHECKING, Any, NamedTuple, TypeVar

if TYPE_CHECKING:
    T = TypeVar('T', bound=NamedTuple)

first line after running autoflake

from typing import NamedTuple, TYPE_CHECKING, TypeVar

which then gets modified if we run isort afterwards

from typing import TYPE_CHECKING, NamedTuple, TypeVar

I suggest this be solved either by adhering to isort's sorting order when removing an import - or not resorting the import objects at all when removing and entirely leaving that up to isort.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions