-
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.
Always place non-relative imports after relative imports (#10669)
## Summary When `relative-imports-order = "closest-to-furthest"` is set, we should _still_ put non-relative imports after relative imports. It's rare for them to be in the same section, but _possible_ if you use `known-local-folder`. Closes #10655. ## Test Plan New tests. Also sorted this file: ```python from ..models import ABC from .models import Question from .utils import create_question from django_polls.apps.polls.models import Choice ``` With both: - `isort view.py` - `ruff check view.py --select I --fix` And the following `pyproject.toml`: ```toml [tool.ruff.lint.isort] order-by-type = false relative-imports-order = "closest-to-furthest" known-local-folder = ["django_polls"] [tool.isort] profile = "black" reverse_relative = true known_local_folder = ["django_polls"] ``` I verified that Ruff and isort gave the same result, and that they _still_ gave the same result when removing the relevant setting: ```toml [tool.ruff.lint.isort] order-by-type = false known-local-folder = ["django_polls"] [tool.isort] profile = "black" known_local_folder = ["django_polls"] ```
- Loading branch information
1 parent
fc54f53
commit 75e0142
Showing
6 changed files
with
86 additions
and
21 deletions.
There are no files selected for viewing
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
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
27 changes: 27 additions & 0 deletions
27
...er__rules__isort__tests__known_local_folder_closest_separate_local_folder_imports.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,27 @@ | ||
--- | ||
source: crates/ruff_linter/src/rules/isort/mod.rs | ||
--- | ||
separate_local_folder_imports.py:1:1: I001 [*] Import block is un-sorted or un-formatted | ||
| | ||
1 | / import sys | ||
2 | | import ruff | ||
3 | | import leading_prefix | ||
4 | | import os | ||
5 | | from . import leading_prefix | ||
6 | | from .. import trailing_prefix | ||
7 | | from ruff import check | ||
| | ||
= help: Organize imports | ||
|
||
ℹ Safe fix | ||
1 |+import os | ||
1 2 | import sys | ||
3 |+ | ||
4 |+import leading_prefix | ||
5 |+ | ||
2 6 | import ruff | ||
3 |-import leading_prefix | ||
4 |-import os | ||
5 7 | from . import leading_prefix | ||
6 8 | from .. import trailing_prefix | ||
7 9 | from ruff import check |
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
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
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