Skip to content

Commit 7dae2f0

Browse files
Fix type handling in visualization_manager.py
1 parent b817d3d commit 7dae2f0

1 file changed

Lines changed: 12 additions & 4 deletions

File tree

src/codegen/visualizations/visualization_manager.py

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import os
2+
from typing import TYPE_CHECKING, Optional, Union
23

34
import plotly.graph_objects as go
45
from networkx import Graph
@@ -7,7 +8,9 @@
78
from codegen.sdk.core.interfaces.editable import Editable
89
from codegen.shared.logging.get_logger import get_logger
910
from codegen.visualizations.viz_utils import graph_to_json
10-
from codegen.visualizations.module_dependency_viz import ModuleDependencyGraph, build_module_dependency_graph
11+
12+
if TYPE_CHECKING:
13+
from codegen.visualizations.module_dependency_viz import ModuleDependencyGraph
1114

1215
logger = get_logger(__name__)
1316

@@ -33,7 +36,7 @@ def clear_graphviz_data(self) -> None:
3336
if self.op.folder_exists(self.viz_path):
3437
self.op.emptydir(self.viz_path)
3538

36-
def write_graphviz_data(self, G: Graph | go.Figure | ModuleDependencyGraph, root: Editable | str | int | None = None) -> None:
39+
def write_graphviz_data(self, G: Union[Graph, go.Figure, "ModuleDependencyGraph"], root: Optional[Union[Editable, str, int]] = None) -> None:
3740
"""Writes the graph data to a file.
3841
3942
Args:
@@ -50,8 +53,13 @@ def write_graphviz_data(self, G: Graph | go.Figure | ModuleDependencyGraph, root
5053
graph_json = graph_to_json(G, root)
5154
elif isinstance(G, go.Figure):
5255
graph_json = G.to_json()
53-
elif isinstance(G, ModuleDependencyGraph):
54-
graph_json = G.to_json(root)
56+
else:
57+
# This is a ModuleDependencyGraph
58+
from codegen.visualizations.module_dependency_viz import ModuleDependencyGraph
59+
if isinstance(G, ModuleDependencyGraph):
60+
graph_json = G.to_json(root)
61+
else:
62+
raise TypeError(f"Unsupported graph type: {type(G)}")
5563

5664
# Check if the visualization path exists, if so, empty it
5765
if self.op.folder_exists(self.viz_path):

0 commit comments

Comments
 (0)