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

Always place non-relative imports after relative imports #10669

Merged
merged 1 commit into from Mar 30, 2024

Conversation

charliermarsh
Copy link
Member

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:

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:

[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:

[tool.ruff.lint.isort]
order-by-type = false
known-local-folder = ["django_polls"]

[tool.isort]
profile = "black"
known_local_folder = ["django_polls"]

@charliermarsh charliermarsh added bug Something isn't working isort Related to import sorting labels Mar 30, 2024
Copy link
Contributor

ruff-ecosystem results

Linter (stable)

✅ ecosystem check detected no linter changes.

Linter (preview)

✅ ecosystem check detected no linter changes.

@charliermarsh charliermarsh merged commit 75e0142 into main Mar 30, 2024
17 checks passed
@charliermarsh charliermarsh deleted the charlie/local branch March 30, 2024 02:13
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 this pull request may close these issues.

isort and ruff behavior mismatch w.r.t. relative imports and relative-imports-order option.
1 participant