You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
from .models import Question
from .utils import create_question
from ..models import ABC
from django_polls.apps.polls.models import Choice
I would prefer the output by isort, but I want to understand the behavior mismatch. I would assume that ruff's relative-imports-order = "closest-to-furthest" is equivalent to isort's reverse_relative = true. Please help me out.
Why is the local folder (django_polls) imports treated as closest rather than relative . and .. imports?
The text was updated successfully, but these errors were encountered:
We probably just never tested because the "local folder" category typically only include relative imports. I would say our behavior is not quite correct, since the relative-imports-order should only affect relative imports, and not other imports in the "local folder" category.
## 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"]
```
I have the following code:
and the following ruff config:
now if I run
ruff check . --select I --fix
, the fixed code is as follows:but with the following isort config:
I get the following:
I would prefer the output by isort, but I want to understand the behavior mismatch. I would assume that ruff's
relative-imports-order = "closest-to-furthest"
is equivalent to isort'sreverse_relative = true
. Please help me out.Why is the local folder (django_polls) imports treated as closest rather than relative
.
and..
imports?The text was updated successfully, but these errors were encountered: