Circular Import Issue Due to Import Reordering in Python 3.8
myousefi opened this issue · 0 comments
myousefi commented
Description
When using isort
to organize imports in our project, we encountered a subtle issue where isort
's reordering of import statements introduced a circular import problem in Python versions 3.8.19. This issue arises specifically in our simulation engine module, where the order of imports is crucial to avoid circular dependencies.
Environment
- Python Version: 3.8
- isort Version: 5.13.2
Minimal Working Example (MWE)
simulation.py
from __future__ import annotations
from .replication_manager import ReplicationManager
class Simulation:
pass
replication_manager.py
from __future__ import annotations
from .simulation import Simulation
class ReplicationManager:
def __init__(self, simulation: Simulation):
self.simulation = simulation
init.py
from .simulation import Simulation
from .replication_manager import ReplicationManager
__all__ = ["Simulation", "ReplicationManager"]
In this example, running isort would reorder the imports in the init file a way that introduces a circular dependency between simulation.py and replication_manager.py.