PyCQA/isort

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

rugved-bodke-stigya opened this issue · 0 comments

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.