Skip to content

Commit 8a6eb8d

Browse files
terapyonterapyon
authored andcommitted
fix ruff check and type errors
1 parent 3422510 commit 8a6eb8d

File tree

6 files changed

+23
-17
lines changed

6 files changed

+23
-17
lines changed

net_vis/adapters/networkx_adapter.py

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ def _detect_graph_type(graph: Any) -> str:
4242
@staticmethod
4343
def _extract_nodes(
4444
graph: Any,
45-
positions: dict[Any, tuple[float, float]],
45+
positions: dict[Any, Any],
4646
node_color: str | Callable | None = None,
4747
node_label: str | Callable | None = None,
4848
) -> list[Node]:
@@ -250,7 +250,7 @@ def _expand_multigraph_edges(
250250
return edges
251251

252252
@staticmethod
253-
def _get_existing_positions(graph: Any) -> dict[Any, tuple[float, float]] | None:
253+
def _get_existing_positions(graph: Any) -> dict[Any, Any] | None:
254254
"""Extract existing 'pos' attribute from nodes.
255255
256256
Args:
@@ -271,7 +271,7 @@ def _get_existing_positions(graph: Any) -> dict[Any, tuple[float, float]] | None
271271
return positions if has_positions else None
272272

273273
@staticmethod
274-
def _apply_spring_layout(graph: Any) -> dict[Any, tuple[float, float]]:
274+
def _apply_spring_layout(graph: Any) -> dict[Any, Any]:
275275
"""Apply spring (force-directed) layout.
276276
277277
Args:
@@ -283,7 +283,7 @@ def _apply_spring_layout(graph: Any) -> dict[Any, tuple[float, float]]:
283283
return nx.spring_layout(graph)
284284

285285
@staticmethod
286-
def _apply_kamada_kawai_layout(graph: Any) -> dict[Any, tuple[float, float]]:
286+
def _apply_kamada_kawai_layout(graph: Any) -> dict[Any, Any]:
287287
"""Apply Kamada-Kawai layout.
288288
289289
Args:
@@ -296,7 +296,7 @@ def _apply_kamada_kawai_layout(graph: Any) -> dict[Any, tuple[float, float]]:
296296
ImportError: If scipy is not installed
297297
"""
298298
try:
299-
import scipy # noqa: F401
299+
import scipy # type: ignore[import-not-found] # noqa: F401
300300
except ImportError:
301301
raise ImportError(
302302
"Layout 'kamada_kawai' requires scipy. "
@@ -306,7 +306,7 @@ def _apply_kamada_kawai_layout(graph: Any) -> dict[Any, tuple[float, float]]:
306306
return nx.kamada_kawai_layout(graph)
307307

308308
@staticmethod
309-
def _apply_spectral_layout(graph: Any) -> dict[Any, tuple[float, float]]:
309+
def _apply_spectral_layout(graph: Any) -> dict[Any, Any]:
310310
"""Apply spectral layout.
311311
312312
Args:
@@ -319,7 +319,7 @@ def _apply_spectral_layout(graph: Any) -> dict[Any, tuple[float, float]]:
319319
ImportError: If scipy is not installed
320320
"""
321321
try:
322-
import scipy # noqa: F401
322+
import scipy # type: ignore[import-not-found] # noqa: F401
323323
except ImportError:
324324
raise ImportError(
325325
"Layout 'spectral' requires scipy. "
@@ -329,7 +329,7 @@ def _apply_spectral_layout(graph: Any) -> dict[Any, tuple[float, float]]:
329329
return nx.spectral_layout(graph)
330330

331331
@staticmethod
332-
def _apply_circular_layout(graph: Any) -> dict[Any, tuple[float, float]]:
332+
def _apply_circular_layout(graph: Any) -> dict[Any, Any]:
333333
"""Apply circular layout.
334334
335335
Args:
@@ -341,7 +341,7 @@ def _apply_circular_layout(graph: Any) -> dict[Any, tuple[float, float]]:
341341
return nx.circular_layout(graph)
342342

343343
@staticmethod
344-
def _apply_random_layout(graph: Any) -> dict[Any, tuple[float, float]]:
344+
def _apply_random_layout(graph: Any) -> dict[Any, Any]:
345345
"""Apply random layout.
346346
347347
Args:
@@ -353,7 +353,7 @@ def _apply_random_layout(graph: Any) -> dict[Any, tuple[float, float]]:
353353
return nx.random_layout(graph)
354354

355355
@staticmethod
356-
def _apply_custom_layout(graph: Any, layout_func: Callable) -> dict[Any, tuple[float, float]]:
356+
def _apply_custom_layout(graph: Any, layout_func: Callable) -> dict[Any, Any]:
357357
"""Apply custom layout function.
358358
359359
Args:
@@ -366,7 +366,7 @@ def _apply_custom_layout(graph: Any, layout_func: Callable) -> dict[Any, tuple[f
366366
return layout_func(graph)
367367

368368
@staticmethod
369-
def _validate_positions(positions: dict[Any, tuple[float, float]]) -> bool:
369+
def _validate_positions(positions: dict[Any, Any]) -> bool:
370370
"""Validate that positions don't contain NaN or inf values.
371371
372372
Args:
@@ -386,7 +386,7 @@ def _validate_positions(positions: dict[Any, tuple[float, float]]) -> bool:
386386
def _compute_layout(
387387
graph: Any,
388388
layout: str | Callable | None = None
389-
) -> dict[Any, tuple[float, float]]:
389+
) -> dict[Any, Any]:
390390
"""Compute node positions using specified layout algorithm.
391391
392392
Args:

net_vis/models.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ def to_dict(self) -> dict[str, Any]:
9292
for layer in self.layers:
9393
# Convert nodes to netvis format
9494
for node in layer.nodes:
95-
node_dict = {
95+
node_dict: dict[str, Any] = {
9696
"id": node.id,
9797
"x": node.x,
9898
"y": node.y,
@@ -107,7 +107,7 @@ def to_dict(self) -> dict[str, Any]:
107107

108108
# Convert edges to netvis format (links)
109109
for edge in layer.edges:
110-
link_dict = {
110+
link_dict: dict[str, Any] = {
111111
"source": edge.source,
112112
"target": edge.target,
113113
}
@@ -119,7 +119,7 @@ def to_dict(self) -> dict[str, Any]:
119119
link_dict.update(edge.metadata)
120120
all_links.append(link_dict)
121121

122-
result = {
122+
result: dict[str, Any] = {
123123
"nodes": all_nodes,
124124
"links": all_links,
125125
}

net_vis/plotter.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
11
"""High-level API for plotting NetworkX graphs in JupyterLab."""
22

33
import json
4-
from typing import Any, Callable
5-
from .models import Scene, GraphLayer
4+
from collections.abc import Callable
5+
from typing import Any
6+
67
from .adapters.networkx_adapter import NetworkXAdapter
8+
from .models import Scene
79

810

911
class Plotter:

net_vis/tests/test_networkx_adapter.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
pytest.importorskip("networkx")
77

88
import networkx as nx
9+
910
from net_vis.adapters.networkx_adapter import NetworkXAdapter
1011

1112

net_vis/tests/test_plotter.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,14 @@
11
"""Tests for Plotter class public API."""
22

33
import json
4+
45
import pytest
56

67
# Skip all tests if networkx is not installed
78
pytest.importorskip("networkx")
89

910
import networkx as nx
11+
1012
from net_vis import Plotter
1113

1214

pyproject.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -134,6 +134,7 @@ exclude = [
134134
".venv",
135135
"venv",
136136
"venv-docker",
137+
"net_vis/tests",
137138
]
138139
pythonVersion = "3.10"
139140
typeCheckingMode = "basic"

0 commit comments

Comments
 (0)