From c7fa963e6a0c9ad56d291b14bfa9deaa2284ba92 Mon Sep 17 00:00:00 2001 From: jpalm3r Date: Fri, 6 Mar 2026 12:12:32 +0100 Subject: [PATCH] Mypy issues: Refactor type annotations for breakpoints and edges in Res1DReach and Network classes --- src/modelskill/model/adapters/_res1d.py | 4 ++-- src/modelskill/model/network.py | 7 +++++-- 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/src/modelskill/model/adapters/_res1d.py b/src/modelskill/model/adapters/_res1d.py index 92b78d1da..c3ec44999 100644 --- a/src/modelskill/model/adapters/_res1d.py +++ b/src/modelskill/model/adapters/_res1d.py @@ -82,7 +82,7 @@ def __init__( self._start = Res1DNode(start_node, {reach.name: start_gridpoint}) self._end = Res1DNode(end_node, {reach.name: end_gridpoint}) self._length = reach.length - self._breakpoints = [ + self._breakpoints: list[EdgeBreakPoint] = [ GridPoint(gridpoint) for gridpoint in intermediate_gridpoints ] @@ -103,5 +103,5 @@ def length(self) -> float: return self._length @property - def breakpoints(self) -> list[GridPoint]: + def breakpoints(self) -> list[EdgeBreakPoint]: return self._breakpoints diff --git a/src/modelskill/model/network.py b/src/modelskill/model/network.py index 163c97cbb..a697b062e 100644 --- a/src/modelskill/model/network.py +++ b/src/modelskill/model/network.py @@ -333,7 +333,7 @@ def breakpoints(self) -> list[EdgeBreakPoint]: class Network: """Network built from a set of edges, with coordinate lookup and data access.""" - def __init__(self, edges: list[NetworkEdge]): + def __init__(self, edges: Sequence[NetworkEdge]): self._edges: dict[str, NetworkEdge] = {e.id: e for e in edges} self._graph = self._initialize_graph() self._alias_map = self._initialize_alias_map() @@ -561,8 +561,11 @@ def find( "Must specify either 'node' or both 'edge' and 'distance' parameters" ) + ids: list[str | tuple[str, float]] + if by_node: # Handle node lookup + assert node is not None if not isinstance(node, list): node = [node] ids = list(node) @@ -673,7 +676,7 @@ def recall(self, id: int | list[int]) -> dict[str, Any] | list[dict[str, Any]]: # Create reverse lookup map reverse_alias_map = {v: k for k, v in self._alias_map.items()} - results = [] + results: list[dict[str, Any]] = [] for node_id in id: if node_id not in reverse_alias_map: raise KeyError(f"Node ID {node_id} not found in the network.")