Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
jakkdl opened this issue Mar 1, 2023 · 3 comments · Fixed by #232
Closed

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

jakkdl opened this issue Mar 1, 2023 · 3 comments · Fixed by #232

Comments

@jakkdl
Copy link

jakkdl commented Mar 1, 2023

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.

@jakkdl
Copy link
Author

jakkdl commented Mar 1, 2023

isort version: 5.12.0
autoflake version: 2.0.1
no config and no flags (other than --in-place for autoflake)

@fsouza
Copy link
Collaborator

fsouza commented Mar 1, 2023

Hmm autoflake should probably not sort anything, just remove the unused ones. Thanks for reporting!

fsouza added a commit that referenced this issue Mar 10, 2023
When removing unused imports or breaking up lines, keep the original
order.

Users can use other linters/formatters to fix import order (e.g. isort
or reorder-python-imports).

Closes #229.
@fsouza
Copy link
Collaborator

fsouza commented Mar 10, 2023

@jakkdl can you give #232 a shot?

@fsouza fsouza closed this as completed in c136ba5 Mar 10, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants