A reactive notebook for Python — run reproducible experiments, query with SQL, execute as a script, deploy as an app, and version with git. Stored as pure Python. All in a modern, AI-native editor.
Python artificial-intelligencedagdata-sciencedata-visualizationdataflowdeveloper-toolsmachine-learningnotebookspipelinepythonreactivesqlweb-app
refactor: convert edges class to util functions, remove unused siblings (#7533)
Myles Scolnickc8ea19cfabf1
diff --git a/marimo/_runtime/dataflow/edges.py b/marimo/_runtime/dataflow/edges.pyindex 34f0d6308b..bde7905af7 100644--- a/marimo/_runtime/dataflow/edges.py+++ b/marimo/_runtime/dataflow/edges.py@@ -20,250 +20,238 @@ from marimo._ast.sql_visitor import SQLTypesLOGGER = _loggers.marimo_logger()-class EdgeComputer:- """Computes graph edges based on cell definitions and references.-- Responsibilities:- - Compute parent/child relationships from defs/refs- - Handle SQL reference resolution- - Handle deleted reference semantics- - Apply language-specific edge rules (Python/SQL)+def get_referring_cells(+ name: Name,+ language: Literal["python", "sql"],+ topology: GraphTopology,+) -> set[CellId_t]:+ """Get all cells that have a ref to `name`.++ The variable can be either a Python variable or a SQL variable (table).+ SQL variables don't leak to Python cells, but Python variables do leak+ to SQL.++ Only does a local analysis of refs, without taking into consideration+ whether refs are defined by other cells."""+ if language == "sql":+ # For SQL, only return SQL cells that reference the name+ cells = set()+ for cid, cell in topology.cells.items():+ if cell.language != "sql":+ continue++ for ref in cell.refs:+ # Direct reference match+ if ref == name:+ cells.add(cid)+ break++ sql_ref = cell.sql_refs.get(ref)++ kind: SQLTypes = "any"+ if name in cell.variable_data:+ variable_data = cell.variable_data[name][-1]+ kind = cast(SQLTypes, variable_data.kind)++ # Hierarchical reference match+ if sql_ref and sql_ref.matches_hierarchical_ref(+ name, ref, kind+ ):+ cells.add(cid)+ break++ return cells+ else:+ # For Python, return all cells that reference the name+ return {+ cid for cid, cell in topology.cells.items() if name in cell.refs+ }+++def _is_valid_cell_reference(+ cell_id: CellId_t, variable_name: Name, topology: GraphTopology+) -> bool:+ """Check if a cell reference is valid and log errors if not."""+ if cell_id not in topology.cells:+ LOGGER.error(+ "Variable %s is defined in cell %s, but is not in the graph",+ variable_name,+ cell_id,+ )+ return False+ return True+++def _resolve_variable_name(+ name: Name,+ other_cell: CellImpl,+ sql_ref: Optional[SQLRef],+ sql_matches: list[tuple[set[CellId_t], Name]],+) -> Name:+ """Resolve the variable name to use when checking if it exists in another cell.++ For regular (non-SQL) references, returns the original name unchanged.+ For SQL hierarchical references, finds the variable name from sql_matches that+ is actually defined in the other_cell.++ Example:+ cell_1: CREATE SCHEMA schema_name+ cell_2: CREATE TABLE schema_name.table_name+ cell_3: FROM schema_name.table_name SELECT *++ When cell_3 references "schema_name.table_name":+ - For cell_1: returns "schema_name" (what cell_1 actually defines)+ - For cell_2: returns "table_name" (what cell_2 actually defines)+ """+ if not sql_ref or name in other_cell.variable_data:+ return name- def __init__(- self,- topology: GraphTopology,- definitions: DefinitionRegistry,- ):- self.topology = topology- self.definitions = definitions-- def get_referring_cells(- self, name: Name, language: Literal["python", "sql"]- ) -> set[CellId_t]:- """Get all cells that have a ref to `name`.-- The variable can be either a Python variable or a SQL variable (table).- SQL variables don't leak to Python cells, but Python variables do leak- to SQL.-- Only does a local analysis of refs, without taking into consideration- whether refs are defined by other cells.- """- if language == "sql":- # For SQL, only return SQL cells that reference the name- cells = set()- for cid, cell in self.topology.cells.items():- if cell.language != "sql":- continue+ # For SQL hierarchical references, find the matching variable name+ for _, matching_variable_name in sql_matches:+ if matching_variable_name in other_cell.variable_data:+ return matching_variable_name- for ref in cell.refs:- # Direct reference match- if ref == name:- cells.add(cid)- break-- sql_ref = cell.sql_refs.get(ref)-- kind: SQLTypes = "any"- if name in cell.variable_data:- variable_data = cell.variable_data[name][-1]- kind = cast(SQLTypes, variable_data.kind)-- # Hierarchical reference match- if sql_ref and sql_ref.matches_hierarchical_ref(- name, ref, kind- ):- cells.add(cid)- break-- return cells- else:- # For Python, return all cells that reference the name- return {- cid- for cid, cell in self.topology.cells.items()- if name in cell.refs- }-- def _is_valid_cell_reference(- self, cell_id: CellId_t, variable_name: Name- ) -> bool:- """Check if a cell reference is valid and log errors if not."""- if cell_id not in self.topology.cells:- LOGGER.error(- "Variable %s is defined in cell %s, but is not in the graph",- variable_name,- cell_id,- )- return False- return True-- def _resolve_variable_name(- self,- name: Name,- other_cell: CellImpl,- sql_ref: Optional[SQLRef],- sql_matches: list[tuple[set[CellId_t], Name]],- ) -> Name:- """Resolve the variable name to use when checking if it exists in another cell.-- For regular (non-SQL) references, returns the original name unchanged.- For SQL hierarchical references, finds the variable name from sql_matches that- is actually defined in the other_cell.-- Example:- cell_1: CREATE SCHEMA schema_name- cell_2: CREATE TABLE schema_name.table_name- cell_3: FROM schema_name.table_name SELECT *-- When cell_3 references "schema_name.table_name":- - For cell_1: returns "schema_name" (what cell_1 actually defines)- - For cell_2: returns "table_name" (what cell_2 actually defines)- """- if not sql_ref or name in other_cell.variable_data:- return name-- # For SQL hierarchical references, find the matching variable name- for _, matching_variable_name in sql_matches:- if matching_variable_name in other_cell.variable_data:- return matching_variable_name+ return name- return name- def compute_edges_for_cell(- self, cell_id: CellId_t, cell: CellImpl- ) -> tuple[set[CellId_t], set[CellId_t]]:- """Compute parent and child edges for a cell being registered.-- Args:- cell_id: The ID this cell is being registered with- cell: The cell to compute edges for-- Returns:- Tuple of (parents, children) where:- - parents: cells that this cell depends on- - children: cells that depend on this cell- """- parents: set[CellId_t] = set()- children: set[CellId_t] = set()-- # First, process the variables that this cell defines. Any cell- # that refers to a defined variable becomes a child of this cell.- for name, variable_data in cell.variable_data.items():- # NB. Only the last definition matters.- # Technically more nuanced with branching statements, but this is- # the best we can do with static analysis.- variable = variable_data[-1]-- # a cell can refer to its own defs, but that doesn't add an- # edge to the dependency graph- referring_cells = self.get_referring_cells(- name,- language=variable.language,- ) - {cell_id}-- children.update(referring_cells)-- # Next, process the cells references. The cell becomes a child- # of cells that define its referenced variables. We also have- # special logic for handling references that are deleted by this cell,- # since cells that delete variables that were defined elsewhere- # are made children of cells that reference that variable.- for name in cell.refs:- # First, for each referenced variable, we add cells that define- # that variable as parents- other_ids_defining_name: set[CellId_t] = (- self.definitions.definitions.get(name, set()) - {cell_id}- )+def compute_edges_for_cell(+ cell_id: CellId_t,+ cell: CellImpl,+ topology: GraphTopology,+ definitions: DefinitionRegistry,+) -> tuple[set[CellId_t], set[CellId_t]]:+ """Compute parent and child edges for a cell being registered.- variable_name: Name = name+ Args:+ cell_id: The ID this cell is being registered with+ cell: The cell to compute edges for+ topology: The graph topology+ definitions: The definition registry- # Handle SQL matching for hierarchical references- sql_matches: list[tuple[set[CellId_t], Name]] = []- sql_ref = cell.sql_refs.get(name)- if sql_ref:- sql_matches = self.definitions.find_sql_hierarchical_matches(- sql_ref- )- for matching_cell_ids, _ in sql_matches:- if cell_id in matching_cell_ids:- LOGGER.debug("Cell %s is referencing itself", cell_id)- continue- other_ids_defining_name.update(matching_cell_ids)-- # If other_ids_defining_name is empty, the user will get a- # NameError at runtime (unless the symbol is a builtin).- for other_id in other_ids_defining_name:- if other_id == cell_id:- LOGGER.error("Cell %s is referencing itself", cell_id)- continue- if not self._is_valid_cell_reference(other_id, variable_name):+ Returns:+ Tuple of (parents, children) where:+ - parents: cells that this cell depends on+ - children: cells that depend on this cell+ """+ parents: set[CellId_t] = set()+ children: set[CellId_t] = set()++ # First, process the variables that this cell defines. Any cell+ # that refers to a defined variable becomes a child of this cell.+ for name, variable_data in cell.variable_data.items():+ # NB. Only the last definition matters.+ # Technically more nuanced with branching statements, but this is+ # the best we can do with static analysis.+ variable = variable_data[-1]++ # a cell can refer to its own defs, but that doesn't add an+ # edge to the dependency graph+ referring_cells = get_referring_cells(+ name,+ language=variable.language,+ topology=topology,+ ) - {cell_id}++ children.update(referring_cells)++ # Next, process the cells references. The cell becomes a child+ # of cells that define its referenced variables. We also have+ # special logic for handling references that are deleted by this cell,+ # since cells that delete variables that were defined elsewhere+ # are made children of cells that reference that variable.+ for name in cell.refs:+ # First, for each referenced variable, we add cells that define+ # that variable as parents+ other_ids_defining_name: set[CellId_t] = definitions.definitions.get(+ name, set()+ ) - {cell_id}++ variable_name: Name = name++ # Handle SQL matching for hierarchical references+ sql_matches: list[tuple[set[CellId_t], Name]] = []+ sql_ref = cell.sql_refs.get(name)+ if sql_ref:+ sql_matches = definitions.find_sql_hierarchical_matches(sql_ref)+ for matching_cell_ids, _ in sql_matches:+ if cell_id in matching_cell_ids:+ LOGGER.debug("Cell %s is referencing itself", cell_id)continue- other_cell = self.topology.cells[other_id]+ other_ids_defining_name.update(matching_cell_ids)++ # If other_ids_defining_name is empty, the user will get a+ # NameError at runtime (unless the symbol is a builtin).+ for other_id in other_ids_defining_name:+ if other_id == cell_id:+ LOGGER.error("Cell %s is referencing itself", cell_id)+ continue+ if not _is_valid_cell_reference(other_id, variable_name, topology):+ continue+ other_cell = topology.cells[other_id]++ variable_name = _resolve_variable_name(+ variable_name, other_cell, sql_ref, sql_matches+ )- variable_name = self._resolve_variable_name(- variable_name, other_cell, sql_ref, sql_matches+ # If we don't have a matching variable name, skip+ if variable_name not in other_cell.variable_data:+ LOGGER.error(+ "Variable %s is not defined in cell %s",+ variable_name,+ other_id,)-- # If we don't have a matching variable name, skip- if variable_name not in other_cell.variable_data:- LOGGER.error(- "Variable %s is not defined in cell %s",- variable_name,- other_id,- )+ continue++ other_variable_data = other_cell.variable_data[variable_name][-1]+ language = other_variable_data.language+ if language == "sql" and cell.language == "python":+ # SQL table/db def -> Python ref is not an edge+ continue+ if language == "sql" and cell.language == "sql":+ # Edges between SQL cells need to respect hierarchy.+ if sql_ref and not sql_ref.matches_hierarchical_ref(+ variable_name,+ other_variable_data.qualified_name or name,+ kind=cast(SQLTypes, other_variable_data.kind),+ ):continue-- other_variable_data = other_cell.variable_data[variable_name][- -1- ]- language = other_variable_data.language- if language == "sql" and cell.language == "python":- # SQL table/db def -> Python ref is not an edge- continue- if language == "sql" and cell.language == "sql":- # Edges between SQL cells need to respect hierarchy.- if sql_ref and not sql_ref.matches_hierarchical_ref(- variable_name,- other_variable_data.qualified_name or name,- kind=cast(SQLTypes, other_variable_data.kind),- ):- continue- parents.add(other_id)-- # Next, any cell that deletes this referenced variable is made- # a child of this cell. In particular, if a cell deletes a- # variable, it becomes a child of all other cells that- # reference that variable. This means that if two cells delete- # the same variable, they form a cycle.- #- # For example, two cells- #- # cell u: x- # cell v: del x- #- # v becomes a child of u.- #- # Another example:- #- # cell u: del x- # cell v: del x- #- # u and v form a cycle.- other_ids_deleting_name: set[CellId_t] = {- cid- for cid in self.get_referring_cells(name, language="python")- if name in self.topology.cells[cid].deleted_refs- } - {cell_id}- children.update(other_ids_deleting_name)-- # Finally, if this cell deletes a variable, we make it a child of- # all other cells that reference this variable.- for name in cell.deleted_refs:- referring_cells = self.get_referring_cells(- name, language="python"- ) - {cell_id}- parents.update(referring_cells)-- return parents, children+ parents.add(other_id)++ # Next, any cell that deletes this referenced variable is made+ # a child of this cell. In particular, if a cell deletes a+ # variable, it becomes a child of all other cells that+ # reference that variable. This means that if two cells delete+ # the same variable, they form a cycle.+ #+ # For example, two cells+ #+ # cell u: x+ # cell v: del x+ #+ # v becomes a child of u.+ #+ # Another example:+ #+ # cell u: del x+ # cell v: del x+ #+ # u and v form a cycle.+ other_ids_deleting_name: set[CellId_t] = {+ cid+ for cid in get_referring_cells(+ name, language="python", topology=topology+ )+ if name in topology.cells[cid].deleted_refs+ } - {cell_id}+ children.update(other_ids_deleting_name)++ # Finally, if this cell deletes a variable, we make it a child of+ # all other cells that reference this variable.+ for name in cell.deleted_refs:+ referring_cells = get_referring_cells(+ name, language="python", topology=topology+ ) - {cell_id}+ parents.update(referring_cells)++ return parents, childrendiff --git a/marimo/_runtime/dataflow/graph.py b/marimo/_runtime/dataflow/graph.pyindex 09aa71f5f2..21e2c27ecd 100644--- a/marimo/_runtime/dataflow/graph.py+++ b/marimo/_runtime/dataflow/graph.py@@ -10,9 +10,9 @@ from typing import TYPE_CHECKING, Callable, Literal, Optionalfrom marimo import _loggersfrom marimo._ast.compiler import code_keyfrom marimo._ast.variables import is_mangled_local+from marimo._runtime.dataflow import edgesfrom marimo._runtime.dataflow.cycles import CycleTrackerfrom marimo._runtime.dataflow.definitions import DefinitionRegistry-from marimo._runtime.dataflow.edges import EdgeComputerfrom marimo._runtime.dataflow.topology import (GraphTopology,MutableGraphTopology,@@ -33,7 +33,7 @@ class DirectedGraph(GraphTopology):"""Main entry point that coordinates all graph operations.Responsibilities:- - Coordinate topology, definitions, cycles, siblings+ - Coordinate topology, definitions, cycles- Execute register_cell/delete_cell operations- Maintain thread safety- Delegate to specialists@@ -47,16 +47,6 @@ class DirectedGraph(GraphTopology):)cycle_tracker: CycleTracker = field(default_factory=CycleTracker)- # Cells that define the same name- #- # siblings[cell_id] is a set of cell ids, one for each cell that shares a- # definition with cell_id.- #- # If this dict is non-empty, then the marimo program contains multiply- # defined names (and is therefore in an error state)- # TODO: remove this field (might be unused)- siblings: dict[CellId_t, set[CellId_t]] = field(default_factory=dict)-# This lock must be acquired during methods that mutate the graph; it's# only needed because a graph is shared between the kernel and the code# completion service. It should almost always be uncontended.@@ -88,8 +78,7 @@ class DirectedGraph(GraphTopology):Only does a local analysis of refs, without taking into considerationwhether refs are defined by other cells."""- edge_computer = EdgeComputer(self.topology, self.definition_registry)- return edge_computer.get_referring_cells(name, language)+ return edges.get_referring_cells(name, language, self.topology)def register_cell(self, cell_id: CellId_t, cell: CellImpl) -> None:"""Add a cell to the graph.@@ -106,27 +95,16 @@ class DirectedGraph(GraphTopology):# Add the cell to topologyself.topology.add_node(cell_id, cell)- # Initialize siblings for this cell- self.siblings[cell_id] = set()-# Process definitions and build sibling relationships FIRST# This must happen before computing edges because edge computation# needs to look up definitionsfor name, variable_data in cell.variable_data.items():- siblings = self.definition_registry.register_definition(+ self.definition_registry.register_definition(cell_id, name, variable_data)- # Update siblings bidirectionally- for sibling in siblings:- self.siblings[cell_id].add(sibling)- self.siblings[sibling].add(cell_id)-- # Now compute edges using EdgeComputer (which can now find the definitions)- edge_computer = EdgeComputer(- self.topology, self.definition_registry- )- parents, children = edge_computer.compute_edges_for_cell(- cell_id, cell+ # Now compute edges (which can now find the definitions)+ parents, children = edges.compute_edges_for_cell(+ cell_id, cell, self.topology, self.definition_registry)# Add edges to topology@@ -235,11 +213,6 @@ class DirectedGraph(GraphTopology):for e in edges:self.cycle_tracker.remove_cycles_with_edge(e)- # Remove from siblings- for sibling_id in self.siblings.get(cell_id, set()):- self.siblings[sibling_id].discard(cell_id)- self.siblings.pop(cell_id, None)-# Purge this cell from the graph topologyself.topology.remove_node(cell_id)diff --git a/marimo/_runtime/runtime.py b/marimo/_runtime/runtime.pyindex 77df4facda..4f83d5420a 100644--- a/marimo/_runtime/runtime.py+++ b/marimo/_runtime/runtime.py@@ -999,11 +999,10 @@ class Kernel:)LOGGER.debug(- "graph:\n\tcell id %s\n\tparents %s\n\tchildren %s\n\tsiblings %s",+ "graph:\n\tcell id %s\n\tparents %s\n\tchildren %s",cell_id,self.graph.parents,self.graph.children,- self.graph.siblings,)# We only return cells that were previously children of cell_iddiff --git a/tests/_runtime/test_edges.py b/tests/_runtime/test_edges.pyindex 2dd8dd897f..82c04a4eaf 100644--- a/tests/_runtime/test_edges.py+++ b/tests/_runtime/test_edges.py@@ -7,8 +7,8 @@ import pytestfrom marimo._ast import compilerfrom marimo._dependencies.dependencies import DependencyManager+from marimo._runtime.dataflow import edgesfrom marimo._runtime.dataflow.definitions import DefinitionRegistry-from marimo._runtime.dataflow.edges import EdgeComputerfrom marimo._runtime.dataflow.topology import MutableGraphTopologyparse_cell = partial(compiler.compile_cell, cell_id="0")@@ -17,21 +17,20 @@ HAS_SQL = DependencyManager.duckdb.has() and DependencyManager.polars.has()class TestEdgeComputer:- """Tests for EdgeComputer class."""+ """Tests for edge computation functions."""def setup_method(self) -> None:"""Set up a fresh topology and definitions for each test."""self.topology = MutableGraphTopology()self.definitions = DefinitionRegistry()- self.edge_computer = EdgeComputer(self.topology, self.definitions)def test_get_referring_cells_python_no_refs(self) -> None:"""Test getting referring cells when no cells reference the variable."""cell1 = parse_cell("x = 1")self.topology.add_node("cell_1", cell1)- referring = self.edge_computer.get_referring_cells(- "x", language="python"+ referring = edges.get_referring_cells(+ "x", language="python", topology=self.topology)assert referring == set()@@ -44,8 +43,8 @@ class TestEdgeComputer:self.topology.add_node("cell_1", cell1)self.topology.add_node("cell_2", cell2)- referring = self.edge_computer.get_referring_cells(- "x", language="python"+ referring = edges.get_referring_cells(+ "x", language="python", topology=self.topology)assert referring == {"cell_2"}@@ -62,8 +61,8 @@ class TestEdgeComputer:self.topology.add_node("cell_3", cell3)self.topology.add_node("cell_4", cell4)- referring = self.edge_computer.get_referring_cells(- "x", language="python"+ referring = edges.get_referring_cells(+ "x", language="python", topology=self.topology)assert referring == {"cell_2", "cell_3", "cell_4"}@@ -74,8 +73,8 @@ class TestEdgeComputer:self.topology.add_node("cell_1", cell1)- referring = self.edge_computer.get_referring_cells(- "x", language="python"+ referring = edges.get_referring_cells(+ "x", language="python", topology=self.topology)# cell_1 both defines and references x, but should be in the result@@ -94,8 +93,8 @@ class TestEdgeComputer:self.definitions.register_definition("cell_1", name, var_data)# Compute edges for cell2- parents, children = self.edge_computer.compute_edges_for_cell(- "cell_2", cell2+ parents, children = edges.compute_edges_for_cell(+ "cell_2", cell2, self.topology, self.definitions)assert parents == {"cell_1"}@@ -118,8 +117,8 @@ class TestEdgeComputer:self.definitions.register_definition("cell_2", name, var_data)# Compute edges for cell3- parents, children = self.edge_computer.compute_edges_for_cell(- "cell_3", cell3+ parents, children = edges.compute_edges_for_cell(+ "cell_3", cell3, self.topology, self.definitions)assert parents == {"cell_1", "cell_2"}@@ -144,8 +143,8 @@ class TestEdgeComputer:self.definitions.register_definition("cell_2", name, var_data)# Compute edges for cell2 (middle cell)- parents, children = self.edge_computer.compute_edges_for_cell(- "cell_2", cell2+ parents, children = edges.compute_edges_for_cell(+ "cell_2", cell2, self.topology, self.definitions)assert parents == {"cell_1"}@@ -157,8 +156,8 @@ class TestEdgeComputer:self.topology.add_node("cell_1", cell1)- parents, children = self.edge_computer.compute_edges_for_cell(- "cell_1", cell1+ parents, children = edges.compute_edges_for_cell(+ "cell_1", cell1, self.topology, self.definitions)assert parents == set()@@ -179,8 +178,8 @@ class TestEdgeComputer:self.definitions.register_definition("cell_1", name, var_data)# Compute edges for cell3 (which deletes x)- parents, children = self.edge_computer.compute_edges_for_cell(- "cell_3", cell3+ parents, children = edges.compute_edges_for_cell(+ "cell_3", cell3, self.topology, self.definitions)# cell3 should become a child of cells that reference x (cell2)@@ -202,13 +201,13 @@ class TestEdgeComputer:self.definitions.register_definition("cell_1", name, var_data)# Compute edges for cell2- parents2, children2 = self.edge_computer.compute_edges_for_cell(- "cell_2", cell2+ parents2, children2 = edges.compute_edges_for_cell(+ "cell_2", cell2, self.topology, self.definitions)# Compute edges for cell3- parents3, children3 = self.edge_computer.compute_edges_for_cell(- "cell_3", cell3+ parents3, children3 = edges.compute_edges_for_cell(+ "cell_3", cell3, self.topology, self.definitions)# Both cells should have cell1 as parent@@ -225,8 +224,8 @@ class TestEdgeComputer:self.topology.add_node("cell_1", cell1)- parents, children = self.edge_computer.compute_edges_for_cell(- "cell_1", cell1+ parents, children = edges.compute_edges_for_cell(+ "cell_1", cell1, self.topology, self.definitions)# A cell doesn't create an edge to itself@@ -254,14 +253,14 @@ class TestEdgeComputer:self.definitions.register_definition("cell_3", name, var_data)# Check cell1's children (only direct children, not grandchildren)- parents1, children1 = self.edge_computer.compute_edges_for_cell(- "cell_1", cell1+ parents1, children1 = edges.compute_edges_for_cell(+ "cell_1", cell1, self.topology, self.definitions)assert children1 == {"cell_2", "cell_3"}# Check cell4's parents (it references b and c, not a directly)- parents4, children4 = self.edge_computer.compute_edges_for_cell(- "cell_4", cell4+ parents4, children4 = edges.compute_edges_for_cell(+ "cell_4", cell4, self.topology, self.definitions)assert parents4 == {"cell_2", "cell_3"}@@ -272,8 +271,8 @@ class TestEdgeComputer:self.topology.add_node("cell_1", cell1)# Should not raise an error, just return empty parents- parents, children = self.edge_computer.compute_edges_for_cell(- "cell_1", cell1+ parents, children = edges.compute_edges_for_cell(+ "cell_1", cell1, self.topology, self.definitions)assert parents == set()@@ -292,8 +291,8 @@ class TestEdgeComputer:self.definitions.register_definition("cell_1", name, var_data)# Compute edges for cell2- parents, children = self.edge_computer.compute_edges_for_cell(- "cell_2", cell2+ parents, children = edges.compute_edges_for_cell(+ "cell_2", cell2, self.topology, self.definitions)assert parents == {"cell_1"}@@ -312,8 +311,8 @@ class TestEdgeComputer:self.definitions.register_definition("cell_1", name, var_data)# Compute edges for cell2- parents, children = self.edge_computer.compute_edges_for_cell(- "cell_2", cell2+ parents, children = edges.compute_edges_for_cell(+ "cell_2", cell2, self.topology, self.definitions)assert parents == {"cell_1"}@@ -336,8 +335,8 @@ class TestEdgeComputer:self.definitions.register_definition(cell_id, name, var_data)# Check last cell's parents- parents, children = self.edge_computer.compute_edges_for_cell(- "cell_4", cells[-1][1]+ parents, children = edges.compute_edges_for_cell(+ "cell_4", cells[-1][1], self.topology, self.definitions)assert parents == {"cell_3"}@@ -356,8 +355,8 @@ class TestEdgeComputer:self.topology.add_node("cell_1", cell1)self.topology.add_node("cell_2", cell2)- referring = self.edge_computer.get_referring_cells(- "df", language="python"+ referring = edges.get_referring_cells(+ "df", language="python", topology=self.topology)assert referring == {"cell_2"}@@ -380,8 +379,8 @@ class TestEdgeComputer:self.definitions.register_definition("cell_1", name, var_data)# Compute edges for cell2 (Python cell)- parents, children = self.edge_computer.compute_edges_for_cell(- "cell_2", cell2+ parents, children = edges.compute_edges_for_cell(+ "cell_2", cell2, self.topology, self.definitions)# SQL definitions should not create edges to Python cells@@ -407,8 +406,8 @@ class TestEdgeComputer:self.definitions.register_definition("cell_2", name, var_data)# Compute edges for cell3- parents, children = self.edge_computer.compute_edges_for_cell(- "cell_3", cell3+ parents, children = edges.compute_edges_for_cell(+ "cell_3", cell3, self.topology, self.definitions)# cell3 should depend on both cells that define x@@ -446,8 +445,8 @@ class TestEdgeComputer:self.definitions.register_definition(cell_id, name, var_data)# Compute edges for cell4- parents4, children4 = self.edge_computer.compute_edges_for_cell(- "cell_4", cell4+ parents4, children4 = edges.compute_edges_for_cell(+ "cell_4", cell4, self.topology, self.definitions)# cell4 should:@@ -460,9 +459,9 @@ class TestEdgeComputer:def test_is_valid_cell_reference_missing_cell(self) -> None:"""Test validation when a cell reference points to a non-existent cell."""- # The _is_valid_cell_reference method logs an error when a cell is not found- result = self.edge_computer._is_valid_cell_reference(- "nonexistent", "some_var"+ # The _is_valid_cell_reference function logs an error when a cell is not found+ result = edges._is_valid_cell_reference(+ "nonexistent", "some_var", self.topology)assert result is False@@ -472,7 +471,7 @@ class TestEdgeComputer:cell1 = parse_cell("x = 1")self.topology.add_node("cell_1", cell1)- result = self.edge_computer._is_valid_cell_reference("cell_1", "x")+ result = edges._is_valid_cell_reference("cell_1", "x", self.topology)assert result is True@@ -489,8 +488,8 @@ class TestEdgeComputer:self.definitions.register_definition("cell_1", name, var_data)# Compute edges for cell2- parents, children = self.edge_computer.compute_edges_for_cell(- "cell_2", cell2+ parents, children = edges.compute_edges_for_cell(+ "cell_2", cell2, self.topology, self.definitions)assert parents == {"cell_1"}@@ -508,8 +507,8 @@ class TestEdgeComputer:self.definitions.register_definition("cell_1", name, var_data)# Compute edges for cell2- parents, children = self.edge_computer.compute_edges_for_cell(- "cell_2", cell2+ parents, children = edges.compute_edges_for_cell(+ "cell_2", cell2, self.topology, self.definitions)assert parents == {"cell_1"}@@ -527,8 +526,8 @@ class TestEdgeComputer:self.definitions.register_definition("cell_1", name, var_data)# Compute edges for cell2- parents, children = self.edge_computer.compute_edges_for_cell(- "cell_2", cell2+ parents, children = edges.compute_edges_for_cell(+ "cell_2", cell2, self.topology, self.definitions)assert parents == {"cell_1"}@@ -552,13 +551,13 @@ class TestEdgeComputer:# All cells should depend on cell1for cell_id in ["cell_2", "cell_3", "cell_4"]:cell = self.topology.cells[cell_id]- parents, children = self.edge_computer.compute_edges_for_cell(- cell_id, cell+ parents, children = edges.compute_edges_for_cell(+ cell_id, cell, self.topology, self.definitions)assert parents == {"cell_1"}# Check that cell1 has all three as children- parents1, children1 = self.edge_computer.compute_edges_for_cell(- "cell_1", cell1+ parents1, children1 = edges.compute_edges_for_cell(+ "cell_1", cell1, self.topology, self.definitions)assert children1 == {"cell_2", "cell_3", "cell_4"}