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

I001 does not use human sort. #1371

Closed
ghuls opened this issue Dec 25, 2022 · 1 comment · Fixed by #1374
Closed

I001 does not use human sort. #1371

ghuls opened this issue Dec 25, 2022 · 1 comment · Fixed by #1374
Assignees
Labels
bug Something isn't working isort Related to import sorting

Comments

@ghuls
Copy link

ghuls commented Dec 25, 2022

I001 does not use human sort like isort.

I001 also does not indicate the lines on which it finds the problem, but always mentions the first line of the file even if the first x lines are correctly sorted.

# Output as generated by: isort --profile=black /tmp/human_sort_import.py
$ ❯ cat /tmp/human_sort_import.py
from numpy import (
    cos,
    int8,
    int16,
    int32,
    int64,
    sin,
    tan,
    uint8,
    uint16,
    uint32,
    uint64,
)
$ ruff --select I001 --ignore F401  --no-cache /tmp/human_sort_import.py 
/tmp/human_sort_import.py:1:1: I001 Import block is un-sorted or un-formatted
Found 1 error(s).
1 potentially fixable with the --fix option.

$ cp -a /tmp/human_sort_import.py /tmp/human_sort_import.fixed.py

$ ruff --select I001 --ignore F401 --no-cache --fix /tmp/human_sort_import.fixed.py 
Found 1 error(s) (1 fixed, 0 remaining).

$ diff -u /tmp/human_sort_import.py /tmp/human_sort_import.fixed.py
--- /tmp/human_sort_import.py	2022-12-25 11:06:19.072930208 +0100
+++ /tmp/human_sort_import.fixed.py	2022-12-25 11:17:51.707302881 +0100
@@ -1,13 +1,13 @@
 from numpy import (
     cos,
-    int8,
     int16,
     int32,
     int64,
+    int8,
     sin,
     tan,
-    uint8,
     uint16,
     uint32,
     uint64,
+    uint8,
 )

$ isort --profile=black /tmp/human_sort_import.fixed.py
Fixing /tmp/human_sort_import.fixed.py

$ diff -u /tmp/human_sort_import.py /tmp/human_sort_import.fixed.py
@charliermarsh charliermarsh added enhancement bug Something isn't working isort Related to import sorting and removed enhancement labels Dec 25, 2022
@charliermarsh
Copy link
Member

Makes sense, thank you! Hopefully easy to fix.

The error ranges could be improved too but it will take a bit more care. Right now, they report based on the start and end of the import block (slew of consecutive imports), since we compare entire blocks at a time.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working isort Related to import sorting
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants