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

isort does not move all imports to the top of the file when there are imports after other code blocks #2274

Open
rugved-bodke-stigya opened this issue Jul 2, 2024 · 0 comments

Comments

@rugved-bodke-stigya
Copy link

When using isort to sort imports, it fails to move all import statements to the top of the file. This issue occurs when there are import statements placed after other code blocks. Below is a minimal example demonstrating the issue:

from tkinter import Button, Label, messagebox, StringVar, Text, Tk, ttk

from dummy_module_1 import DummyClass1
from dummy_module_2 import DummyClass2
from dummy_module_3 import DummyClass3
from dummy_module_4 import DummyClass4

# Some configuration variable
config_flag = True

# Create an instance of tkinter frame
app = Tk()
if config_flag:
    app.title("Live - Dummy App")
else:
    app.title("Test - Dummy App")

app.geometry("350x450")
app.resizable(False, False)
from dummy_module_5 import DummyClass5
[tool.isort]
profile = "black"
multi_line_output = 3
line_length = 88
include_trailing_comma = true
lines_after_imports = 2
lines_between_types = 0
use_parentheses = true
src_paths = ["src"]
skip = ["extras", "data"]

[tool.black]
line_length = 88

Steps to Reproduce
Save the example code to src/some_file.py.

Run isort on the file:

python -m isort src/some_file.py

Observe that the import statement from dummy_module_5 import DummyClass5 remains at the bottom of the file, below other code.
Expected Behavior
All import statements should be moved to the top of the file, sorted according to the configuration.

Actual Behavior
The import statement from dummy_module_5 import DummyClass5 is not moved to the top of the file and remains below other code.

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

No branches or pull requests

1 participant