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

fix(isort): comply with isort when sorting sub-package modules #3064

Closed
wants to merge 1 commit into from

Conversation

spaceone
Copy link
Contributor

@spaceone spaceone commented Feb 20, 2023

e.g. packages named "foo.bar"

additionally make sure __future__ imports are always sorted at the very top.

Fixes #3059

@spaceone spaceone marked this pull request as draft February 20, 2023 18:49
@spaceone spaceone marked this pull request as ready for review February 20, 2023 19:40
} else if known_local_folder.contains(module_name) {
(ImportType::LocalFolder, Reason::KnownLocalFolder)
} else if extra_standard_library.contains(module_name) {
(ImportType::StandardLibrary, Reason::ExtraStandardLibrary)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What does isort do if you have:

known-first-party = ["foo"]
known-third-party = ["foo.bar"]

And then you import foo.bar.baz. Does that get classified as first- or third-party?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[settings]
known_first_party=foo
known_third_party=foo.bar

results in:

import sys

import foo.bar
import foo.bar.baz
from foo.bar import blah, blub
from foo.bar.baz import something

import foo
from foo import bar, baz

So my MR currently has this diff:

ruff --select I --fix --diff foo.py 
--- foo.py
+++ foo.py
@@ -1,9 +1,9 @@
 import sys
 
 import foo.bar
-import foo.bar.baz
 from foo.bar import blah, blub
-from foo.bar.baz import something
 
 import foo
+import foo.bar.baz
 from foo import bar, baz
+from foo.bar.baz import something

Would fix 1 error.

@spaceone spaceone marked this pull request as draft February 22, 2023 17:50
e.g. packages named "foo.bar"

additionally make sure `__future__` imports are always sorted at the
very top.

Issue astral-sh#3059
@charliermarsh
Copy link
Member

I'm going to close this for now, just to keep the open PR list tight. If you choose to return to this, we can always reopen!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

isort: bug in sorting sub-package modules
2 participants