Skip to content

Commit f1e225b

Browse files
committed
Fix static analysis
1 parent f7c4a6c commit f1e225b

File tree

7 files changed

+11
-9
lines changed

7 files changed

+11
-9
lines changed

pyproject.toml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,8 @@ dev = [
2424
"mypy",
2525
"pycodestyle",
2626
"coverage",
27+
"types-networkx", # Type hints for networkx
28+
"types-requests", # Type hints for requests
2729
]
2830

2931
[tool.setuptools]

semantic_matcher/algorithm.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -132,7 +132,9 @@ def find_semantic_matches(
132132

133133
# Traverse to the neighboring and therefore connected `semantic_id`s
134134
for neighbor, edge_data in graph[node].items():
135-
new_score: float = score * edge_data["weight"] # Multiplicative propagation
135+
edge_weight = edge_data["weight"]
136+
assert isinstance(edge_weight, float)
137+
new_score: float = score * edge_weight # Multiplicative propagation
136138

137139
# Prevent loops by ensuring we do not revisit the start node after the first iteration
138140
if neighbor == semantic_id:

semantic_matcher/py.typed

Whitespace-only changes.

semantic_matcher/service.py

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,6 @@ def get_all_matches(self):
8080
matches = self.graph.get_all_matches()
8181
return matches
8282

83-
8483
def get_matches(
8584
self,
8685
request_body: MatchRequest
@@ -134,8 +133,6 @@ def get_matches(
134133
score_limit=float(request_body.score_limit/match.score),
135134
# If we already request a remote score, it does not make sense to choose `local_only`
136135
local_only=False,
137-
name=request_body.name,
138-
definition=request_body.definition,
139136
already_checked_locations=already_checked_locations
140137
)
141138
url = f"{remote_matching_service}/get_matches"

semantic_matcher/visualization.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import matplotlib.pyplot as plt
1+
import matplotlib.pyplot as plt # type: ignore
22
import networkx as nx
33

44
from semantic_matcher.algorithm import SemanticMatchGraph

test/test_algorithm.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -38,21 +38,21 @@ def test_get_all_matches_empty_graph(self):
3838
"""Test that an empty graph returns an empty list."""
3939
empty_graph = algorithm.SemanticMatchGraph()
4040
matches = empty_graph.get_all_matches()
41-
self.assertEqual([], matches,"Empty graph should return an empty list.")
41+
self.assertEqual([], matches, "Empty graph should return an empty list.")
4242

4343
def test_get_all_matches_duplicate_edges(self):
4444
"""Test handling of duplicate edges with different scores."""
4545
self.graph.add_semantic_match("A", "B", 0.9) # Overwriting edge
4646
matches = self.graph.get_all_matches()
4747

4848
expected_matches = [
49-
algorithm.SemanticMatch(base_semantic_id="A", match_semantic_id="B", score=0.9, path=[]), # Overwritten edge
49+
algorithm.SemanticMatch(base_semantic_id="A", match_semantic_id="B", score=0.9, path=[]),
5050
algorithm.SemanticMatch(base_semantic_id="B", match_semantic_id="C", score=0.6, path=[]),
5151
algorithm.SemanticMatch(base_semantic_id="C", match_semantic_id="D", score=0.9, path=[]),
5252
]
5353

5454
self.assertEqual(len(matches), 3, "Duplicate edge handling failed.")
55-
self.assertCountEqual(expected_matches, matches,"Matches do not match expected results.")
55+
self.assertCountEqual(expected_matches, matches, "Matches do not match expected results.")
5656

5757
def test_get_all_matches_varying_weights(self):
5858
"""Test that matches with different weights are retrieved correctly."""
@@ -352,5 +352,6 @@ def test_complex_graph(self):
352352
]
353353
self.assertEqual(expected, matches_str)
354354

355+
355356
if __name__ == "__main__":
356357
unittest.main()

test/test_semantic_matcher.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ def run_server_context():
8484
os.kill(server_process.pid, signal.SIGKILL)
8585
server_process.join()
8686

87-
# @unittest.skip("These tests need to be adapted")
87+
8888
class TestSemanticMatchingService(unittest.TestCase):
8989
def test_get_all_matches(self):
9090
with run_server_context():

0 commit comments

Comments
 (0)