77from contextlib import ExitStack , redirect_stdout
88from dataclasses import dataclass
99from pathlib import Path
10+ from typing import cast
1011from unittest .mock import patch
1112
1213import numpy as np
@@ -186,7 +187,8 @@ def _make_bounds(*, dv_limit: float, dacc: float, dangle: float) -> dict[str, fl
186187
187188
188189def _rounded_position (pos : np .ndarray ) -> tuple [float , float , float ]:
189- return tuple (round (float (value ), 5 ) for value in pos )
190+ values = tuple (round (float (value ), 5 ) for value in pos )
191+ return cast (tuple [float , float , float ], values )
190192
191193
192194def _snapshot_graph (snapshot ):
@@ -359,7 +361,7 @@ def _write_synthetic_tracking_fixture(
359361
360362 for frame_index , frame_num in enumerate (FRAMES ):
361363 frame = Frame (3 , 16 )
362- cam_targets = [[] for _ in range (3 )]
364+ cam_targets : list [ list [ Target ]] = [[] for _ in range (3 )]
363365 correspond_indices = {
364366 track_id : [CORRES_NONE ] * 4
365367 for track_id , positions in tracks .items ()
@@ -427,7 +429,9 @@ def _write_synthetic_tracking_fixture(
427429 correspond_indices [track_id ],
428430 dtype = np .int32 ,
429431 )
430- frame .path_info [row_index ].x = tracks [track_id ][frame_index ]
432+ position = tracks [track_id ][frame_index ]
433+ assert position is not None
434+ frame .path_info [row_index ].x = position
431435
432436 write_path_frame (
433437 frame .correspond ,
@@ -446,7 +450,10 @@ def _snapshot_tracking_outputs() -> dict[
446450 int , list [tuple [int , int , tuple [int , int , int , int ], tuple [float , float , float ]]]
447451]:
448452 """Read the written tracking outputs into a stable frame-by-frame snapshot."""
449- snapshots = {}
453+ snapshots : dict [
454+ int ,
455+ list [tuple [int , int , tuple [int , int , int , int ], tuple [float , float , float ]]],
456+ ] = {}
450457 for frame in FRAMES :
451458 correspond , path_info = read_path_frame (
452459 "res/particles" ,
@@ -458,8 +465,14 @@ def _snapshot_tracking_outputs() -> dict[
458465 (
459466 int (path .prev_frame ),
460467 int (path .next_frame ),
461- tuple (int (value ) for value in correspond [idx ].p ),
462- tuple (round (float (value ), 5 ) for value in path .x ),
468+ cast (
469+ tuple [int , int , int , int ],
470+ tuple (int (value ) for value in correspond [idx ].p ),
471+ ),
472+ cast (
473+ tuple [float , float , float ],
474+ tuple (round (float (value ), 5 ) for value in path .x ),
475+ ),
463476 )
464477 for idx , path in enumerate (path_info )
465478 ]
0 commit comments