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

Circular Import Issue Due to Import Reordering in Python 3.8 #2259

Open
myousefi opened this issue Apr 18, 2024 · 0 comments
Open

Circular Import Issue Due to Import Reordering in Python 3.8 #2259

myousefi opened this issue Apr 18, 2024 · 0 comments

Comments

@myousefi
Copy link

myousefi commented Apr 18, 2024

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.

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