Skip to content

Commit d1f4b8b

Browse files
fix mypy (#1167)
* old numpy forced old version of rerun * fix other mypy issues
1 parent 7052565 commit d1f4b8b

File tree

9 files changed

+58
-44
lines changed

9 files changed

+58
-44
lines changed

dimos/models/depth/metric3d.py

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,10 @@ def infer_depth(self, img, debug: bool = False): # type: ignore[no-untyped-def]
7878
try:
7979
if isinstance(img, str):
8080
print(f"Image type string: {type(img)}")
81-
self.rgb_origin = cv2.imread(img)[:, :, ::-1]
81+
img_data = cv2.imread(img)
82+
if img_data is None:
83+
raise ValueError(f"Failed to load image from {img}")
84+
self.rgb_origin = img_data[:, :, ::-1]
8285
else:
8386
# print(f"Image type not string: {type(img)}, cv2 conversion assumed to be handled. If not, this will throw an error")
8487
self.rgb_origin = img
@@ -172,9 +175,11 @@ def unpad_transform_depth(self, pred_depth): # type: ignore[no-untyped-def]
172175

173176
def eval_predicted_depth(self, depth_file, pred_depth) -> None: # type: ignore[no-untyped-def]
174177
if depth_file is not None:
175-
gt_depth = cv2.imread(depth_file, -1)
176-
gt_depth = gt_depth / self.gt_depth_scale # type: ignore[assignment]
177-
gt_depth = torch.from_numpy(gt_depth).float().to(self.device) # type: ignore[assignment]
178+
gt_depth_np = cv2.imread(depth_file, -1)
179+
if gt_depth_np is None:
180+
raise ValueError(f"Failed to load depth file from {depth_file}")
181+
gt_depth_scaled = gt_depth_np / self.gt_depth_scale
182+
gt_depth = torch.from_numpy(gt_depth_scaled).float().to(self.device)
178183
assert gt_depth.shape == pred_depth.shape
179184

180185
mask = gt_depth > 1e-8

dimos/models/segmentation/edge_tam.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@
3636
from dimos.utils.logging_config import setup_logger
3737

3838
if TYPE_CHECKING:
39-
from sam2.sam2_video_predictor import SAM2VideoPredictor # type: ignore[import-untyped]
39+
from sam2.sam2_video_predictor import SAM2VideoPredictor
4040

4141
os.environ['TQDM_DISABLE'] = '1'
4242

dimos/perception/detection/type/detection2d/seg.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -183,8 +183,10 @@ def to_points_annotation(self) -> list[PointsAnnotation]:
183183
approx = cv2.approxPolyDP(contour, epsilon, True)
184184

185185
points = []
186-
for pt in approx:
187-
points.append(Point2(x=float(pt[0][0]), y=float(pt[0][1])))
186+
for i in range(len(approx)):
187+
x_coord = float(approx[i, 0, 0])
188+
y_coord = float(approx[i, 0, 1])
189+
points.append(Point2(x=x_coord, y=y_coord))
188190

189191
if len(points) < 3:
190192
continue

dimos/protocol/pubsub/benchmark/testdata.py

Lines changed: 22 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414

1515
from collections.abc import Generator
1616
from contextlib import contextmanager
17-
from typing import Any
17+
from typing import TYPE_CHECKING, Any
1818

1919
import numpy as np
2020

@@ -211,13 +211,21 @@ def redis_msggen(size: int) -> tuple[str, Any]:
211211
ROSTopic,
212212
)
213213

214+
if TYPE_CHECKING:
215+
from numpy.typing import NDArray
216+
214217
if ROS_AVAILABLE:
215-
from rclpy.qos import QoSDurabilityPolicy, QoSHistoryPolicy, QoSProfile, QoSReliabilityPolicy
216-
from sensor_msgs.msg import Image as ROSImage
218+
from rclpy.qos import ( # type: ignore[no-untyped-call]
219+
QoSDurabilityPolicy,
220+
QoSHistoryPolicy,
221+
QoSProfile,
222+
QoSReliabilityPolicy,
223+
)
224+
from sensor_msgs.msg import Image as ROSImage # type: ignore[attr-defined,no-untyped-call]
217225

218226
@contextmanager
219227
def ros_best_effort_pubsub_channel() -> Generator[RawROS, None, None]:
220-
qos = QoSProfile(
228+
qos = QoSProfile( # type: ignore[no-untyped-call]
221229
reliability=QoSReliabilityPolicy.BEST_EFFORT,
222230
history=QoSHistoryPolicy.KEEP_LAST,
223231
durability=QoSDurabilityPolicy.VOLATILE,
@@ -230,7 +238,7 @@ def ros_best_effort_pubsub_channel() -> Generator[RawROS, None, None]:
230238

231239
@contextmanager
232240
def ros_reliable_pubsub_channel() -> Generator[RawROS, None, None]:
233-
qos = QoSProfile(
241+
qos = QoSProfile( # type: ignore[no-untyped-call]
234242
reliability=QoSReliabilityPolicy.RELIABLE,
235243
history=QoSHistoryPolicy.KEEP_LAST,
236244
durability=QoSDurabilityPolicy.VOLATILE,
@@ -245,21 +253,21 @@ def ros_msggen(size: int) -> tuple[RawROSTopic, ROSImage]:
245253
import numpy as np
246254

247255
# Create image data
248-
data = np.frombuffer(make_data_bytes(size), dtype=np.uint8).reshape(-1)
249-
padded_size = ((len(data) + 2) // 3) * 3
250-
data = np.pad(data, (0, padded_size - len(data)))
251-
pixels = len(data) // 3
256+
raw_data: NDArray[np.uint8] = np.frombuffer(make_data_bytes(size), dtype=np.uint8)
257+
padded_size = ((len(raw_data) + 2) // 3) * 3
258+
padded_data: NDArray[np.uint8] = np.pad(raw_data, (0, padded_size - len(raw_data)))
259+
pixels = len(padded_data) // 3
252260
height = max(1, int(pixels**0.5))
253261
width = pixels // height
254-
data = data[: height * width * 3]
262+
final_data: NDArray[np.uint8] = padded_data[: height * width * 3]
255263

256264
# Create ROS Image message
257-
msg = ROSImage()
265+
msg = ROSImage() # type: ignore[no-untyped-call]
258266
msg.height = height
259267
msg.width = width
260268
msg.encoding = "rgb8"
261269
msg.step = width * 3
262-
msg.data = data.tobytes()
270+
msg.data = bytes(final_data)
263271

264272
topic = RawROSTopic(topic="/benchmark/ros", ros_type=ROSImage)
265273
return (topic, msg)
@@ -280,7 +288,7 @@ def ros_msggen(size: int) -> tuple[RawROSTopic, ROSImage]:
280288

281289
@contextmanager
282290
def dimos_ros_best_effort_pubsub_channel() -> Generator[DimosROS, None, None]:
283-
qos = QoSProfile(
291+
qos = QoSProfile( # type: ignore[no-untyped-call]
284292
reliability=QoSReliabilityPolicy.BEST_EFFORT,
285293
history=QoSHistoryPolicy.KEEP_LAST,
286294
durability=QoSDurabilityPolicy.VOLATILE,
@@ -293,7 +301,7 @@ def dimos_ros_best_effort_pubsub_channel() -> Generator[DimosROS, None, None]:
293301

294302
@contextmanager
295303
def dimos_ros_reliable_pubsub_channel() -> Generator[DimosROS, None, None]:
296-
qos = QoSProfile(
304+
qos = QoSProfile( # type: ignore[no-untyped-call]
297305
reliability=QoSReliabilityPolicy.RELIABLE,
298306
history=QoSHistoryPolicy.KEEP_LAST,
299307
durability=QoSDurabilityPolicy.VOLATILE,

dimos/protocol/pubsub/impl/rospubsub.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@ def __init__(self, node_name: str | None = None, qos: "QoSProfile | None" = None
104104
if qos is not None:
105105
self._qos = qos
106106
else:
107-
self._qos = QoSProfile(
107+
self._qos = QoSProfile( # type: ignore[no-untyped-call]
108108
# Haven't noticed any difference between BEST_EFFORT and RELIABLE for local comms in our tests
109109
# ./bin/dev python -m pytest -svm tool -k ros dimos/protocol/pubsub/benchmark/test_benchmark.py
110110
#
@@ -120,7 +120,7 @@ def start(self) -> None:
120120
if self._spin_thread is not None:
121121
return
122122

123-
if not rclpy.ok():
123+
if not rclpy.ok(): # type: ignore[attr-defined]
124124
rclpy.init()
125125

126126
self._stop_event.clear()
@@ -160,7 +160,7 @@ def stop(self) -> None:
160160
self._node.destroy_publisher(publisher)
161161

162162
if self._node:
163-
self._node.destroy_node()
163+
self._node.destroy_node() # type: ignore[no-untyped-call]
164164
self._node = None
165165

166166
self._executor = None

dimos/spec/utils.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
import inspect
1616
from typing import Any, Protocol, runtime_checkable
1717

18-
from annotation_protocol import AnnotationProtocol # type: ignore[import-untyped]
18+
from annotation_protocol import AnnotationProtocol
1919
from typing_extensions import is_protocol
2020

2121

dimos/utils/docs/doclinks.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -529,7 +529,7 @@ def process_file(md_path: Path, quiet: bool = False) -> tuple[bool, list[str]]:
529529

530530
watch_paths = args.paths if args.paths else [str(root / "docs")]
531531

532-
class MarkdownHandler(FileSystemEventHandler):
532+
class MarkdownHandler(FileSystemEventHandler): # type: ignore[misc]
533533
def on_modified(self, event: Any) -> None:
534534
if not event.is_directory and event.src_path.endswith(".md"):
535535
process_file(Path(event.src_path))

docker/ros/Dockerfile

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -43,9 +43,6 @@ RUN apt-get install -y \
4343
qtbase5-dev-tools \
4444
supervisor
4545

46-
# Install specific numpy version first
47-
RUN pip install 'numpy<2.0.0'
48-
4946
# Add ROS2 apt repository
5047
RUN curl -sSL https://raw.githubusercontent.com/ros/rosdistro/master/ros.key -o /usr/share/keyrings/ros-archive-keyring.gpg && \
5148
echo "deb [arch=$(dpkg --print-architecture) signed-by=/usr/share/keyrings/ros-archive-keyring.gpg] http://packages.ros.org/ros2/ubuntu $(lsb_release -cs) main" | tee /etc/apt/sources.list.d/ros2.list > /dev/null
@@ -87,5 +84,3 @@ RUN rosdep update
8784

8885
# Source ROS2 and workspace in bashrc
8986
RUN echo "source /opt/ros/${ROS_DISTRO}/setup.bash" >> /root/.bashrc
90-
91-
# Trigger docker workflow rerun 1

pyproject.toml

Lines changed: 17 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -323,27 +323,31 @@ exclude = "^dimos/models/Detic(/|$)|^dimos/rxpy_backpressure(/|$)|.*/test_.|.*/c
323323

324324
[[tool.mypy.overrides]]
325325
module = [
326-
"rclpy.*",
327-
"std_msgs.*",
326+
"annotation_protocol",
327+
"dimos_lcm.*",
328+
"etils",
328329
"geometry_msgs.*",
329-
"sensor_msgs.*",
330-
"nav_msgs.*",
331-
"tf2_msgs.*",
332330
"mujoco",
333331
"mujoco_playground.*",
334-
"etils",
335-
"xarm.*",
336-
"dimos_lcm.*",
332+
"nav_msgs.*",
333+
"open_clip",
337334
"piper_sdk.*",
335+
"plotext",
338336
"plum.*",
339-
"pycuda.*",
340337
"pycuda",
341-
"plotext",
342-
"torchreid",
343-
"open_clip",
344-
"pyzed.*",
338+
"pycuda.*",
345339
"pyzed",
340+
"pyzed.*",
341+
"rclpy.*",
342+
"sam2.*",
343+
"sensor_msgs.*",
344+
"std_msgs.*",
345+
"tf2_msgs.*",
346+
"torchreid",
347+
"ultralytics.*",
346348
"unitree_webrtc_connect.*",
349+
"watchdog.*",
350+
"xarm.*",
347351
]
348352
ignore_missing_imports = true
349353

0 commit comments

Comments
 (0)