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
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.
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:
Steps to Reproduce Save the example code to src/some_file.py.
Run isort on the file:
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.