Skip to content

Commit 4a941e8

Browse files
committed
stricter type checking
1 parent a135a95 commit 4a941e8

9 files changed

Lines changed: 13 additions & 11 deletions

File tree

solvor/a_star.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ def astar[S](
6767
max_cost: float | None = None,
6868
) -> Result:
6969
"""A* search with heuristic guidance, returns optimal path when weight=1."""
70-
is_goal = goal if callable(goal) else lambda s: s == goal
70+
is_goal: Callable[[S], bool] = goal if callable(goal) else lambda s: s == goal # ty: ignore[invalid-assignment]
7171

7272
g: dict[S, float] = {start: 0.0}
7373
parent: dict[S, S] = {}

solvor/anneal.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -100,8 +100,9 @@ def anneal[T](
100100
rng = Random(seed)
101101
evaluate = Evaluator(objective_fn, minimize)
102102

103+
schedule: CoolingSchedule
103104
if callable(cooling):
104-
schedule = cooling
105+
schedule = cooling # ty: ignore[invalid-assignment]
105106
else:
106107
schedule = exponential_cooling(cooling)
107108

solvor/bfs.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ def bfs[S](
5656
max_iter: int = 1_000_000,
5757
) -> Result:
5858
"""Breadth-first search, guarantees shortest path in unweighted graphs."""
59-
is_goal = (lambda s: s == goal) if not callable(goal) and goal is not None else goal
59+
is_goal: Callable[[S], bool] | None = (lambda s: s == goal) if not callable(goal) and goal is not None else goal # ty: ignore[invalid-assignment]
6060

6161
parent: dict[S, S] = {}
6262
visited: set[S] = {start}
@@ -93,7 +93,7 @@ def dfs[S](
9393
max_iter: int = 1_000_000,
9494
) -> Result:
9595
"""Depth-first search, finds a path (not necessarily shortest)."""
96-
is_goal = (lambda s: s == goal) if not callable(goal) and goal is not None else goal
96+
is_goal: Callable[[S], bool] | None = (lambda s: s == goal) if not callable(goal) and goal is not None else goal # ty: ignore[invalid-assignment]
9797

9898
parent: dict[S, S] = {}
9999
visited: set[S] = {start}

solvor/cp_encoder.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -541,7 +541,7 @@ def decode_sat_solution(sat_sol: dict[int, bool]) -> dict[str, int]:
541541
break
542542
return cp_sol
543543

544-
solution = decode_sat_solution(sat_result.solution) # type: ignore[arg-type]
544+
solution = decode_sat_solution(sat_result.solution)
545545

546546
if sat_result.solutions is not None:
547547
cp_solutions = tuple(decode_sat_solution(s) for s in sat_result.solutions)

solvor/dijkstra.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ def dijkstra[S](
5757
max_cost: float | None = None,
5858
) -> Result:
5959
"""Find shortest path in a weighted graph with non-negative edges."""
60-
is_goal = goal if callable(goal) else lambda s: s == goal
60+
is_goal: Callable[[S], bool] = goal if callable(goal) else lambda s: s == goal # ty: ignore[invalid-assignment]
6161

6262
g: dict[S, float] = {start: 0.0}
6363
parent: dict[S, S] = {}

solvor/dlx.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -161,6 +161,7 @@ def _build_links(matrix, columns=None, secondary=None):
161161
first = node
162162
prev_node = node
163163
else:
164+
assert prev_node is not None
164165
node.left = prev_node
165166
prev_node.right = node
166167
prev_node = node

solvor/flow.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@
4242

4343

4444
def max_flow[Node](
45-
graph: dict[Node, list[tuple[Node, int, ...]]],
45+
graph: dict[Node, list[tuple[Node, int] | tuple[Node, int, int]]],
4646
source: Node,
4747
sink: Node,
4848
) -> Result:
@@ -202,7 +202,7 @@ def solve_assignment(
202202
result = min_cost_flow(graph, source, sink, min(n, m))
203203

204204
assignment = [-1] * n
205-
flow_solution: dict[tuple[str, str], float] = result.solution # type: ignore[assignment]
205+
flow_solution: dict[tuple[str, str], float] = result.solution
206206
for (u, v), f in flow_solution.items():
207207
if f > 0 and u.startswith("L") and v.startswith("R"):
208208
i = int(u[1:])

solvor/rust/__init__.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -154,9 +154,9 @@ def floyd_warshall(n_nodes, edges, *, directed=True) -> Result:
154154

155155
@functools.wraps(fn)
156156
def wrapper(
157-
*args: P.args,
157+
*args,
158158
backend: Literal["auto", "rust", "python"] | None = None,
159-
**kwargs: P.kwargs,
159+
**kwargs,
160160
) -> T:
161161
selected = get_backend(backend)
162162
if selected == "rust":

uv.lock

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)