-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix ordering for
force-sort-within-sections
(#8665)
Fixes #8661 ## Summary Imports like `from x import y` don't have an "asname" for the module, so they were placed before imports like `import x as w` since `None` < `Some(s)` for any string s. The fix is to first sort by `first_alias`, since it's `None` for `import x as w`, and then by `asname`. ## Test Plan I included the example from the issue to avoid future regressions.
- Loading branch information
Showing
4 changed files
with
33 additions
and
2 deletions.
There are no files selected for viewing
5 changes: 5 additions & 0 deletions
5
crates/ruff_linter/resources/test/fixtures/isort/force_sort_within_sections_with_as_names.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
import encodings | ||
from datetime import timezone as tz | ||
from datetime import timedelta | ||
import datetime as dt | ||
import datetime |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
25 changes: 25 additions & 0 deletions
25
...isort__tests__force_sort_within_sections_force_sort_within_sections_with_as_names.py.snap
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
--- | ||
source: crates/ruff_linter/src/rules/isort/mod.rs | ||
--- | ||
force_sort_within_sections_with_as_names.py:1:1: I001 [*] Import block is un-sorted or un-formatted | ||
| | ||
1 | / import encodings | ||
2 | | from datetime import timezone as tz | ||
3 | | from datetime import timedelta | ||
4 | | import datetime as dt | ||
5 | | import datetime | ||
| | ||
= help: Organize imports | ||
|
||
ℹ Safe fix | ||
1 |+import datetime | ||
2 |+import datetime as dt | ||
3 |+from datetime import timedelta | ||
4 |+from datetime import timezone as tz | ||
1 5 | import encodings | ||
2 |-from datetime import timezone as tz | ||
3 |-from datetime import timedelta | ||
4 |-import datetime as dt | ||
5 |-import datetime | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters