chore(robots): enable mypy type checking for robots module#3067
chore(robots): enable mypy type checking for robots module#3067jameslcowan wants to merge 2 commits intohuggingface:mainfrom
Conversation
There was a problem hiding this comment.
Pull request overview
Enables mypy type-checking for lerobot.robots.* and resolves type errors in the robots module as part of the repo-wide mypy compliance effort (Fixes #1721, contributes to #1719).
Changes:
- Enable
lerobot.robots.*mypy override inpyproject.toml. - Add/adjust type annotations in multiple robot implementations (e.g., ZMQ sockets, camera dicts, threads, gains).
- Fix a mypy union-attribute issue in the SO follower kinematic processor by guarding a
.copy()call.
Reviewed changes
Copilot reviewed 6 out of 6 changed files in this pull request and generated 2 comments.
Show a summary per file
| File | Description |
|---|---|
src/lerobot/robots/unitree_g1/unitree_g1.py |
Adds explicit attribute annotations for simulation env, subscriber thread, and controller gains. |
src/lerobot/robots/so_follower/robot_kinematic_processor.py |
Makes observation copying safe under None by splitting retrieval vs copy. |
src/lerobot/robots/lekiwi/lekiwi_host.py |
Adjusts duration initialization to a float for type consistency. |
src/lerobot/robots/lekiwi/lekiwi_client.py |
Adds Any annotations for ZMQ handles and internal dicts; makes is_calibrated return a boolean. |
src/lerobot/robots/earthrover_mini_plus/robot_earthrover_mini_plus.py |
Adds typing for cameras and suppresses untyped import checking for requests. |
pyproject.toml |
Turns on mypy checking for the lerobot.robots.* module override. |
Comments suppressed due to low confidence (1)
src/lerobot/robots/so_follower/robot_kinematic_processor.py:568
q_rawis created withnp.array(...)and will never beNone, so theif q_raw is None:branch is unreachable. If you want to validate missing joint positions, check for an empty result (e.g., zero-sized array) or validate expected keys before buildingq_raw.
q_raw = np.array(
[float(v) for k, v in observation.items() if isinstance(k, str) and k.endswith(".pos")],
dtype=float,
)
if q_raw is None:
raise ValueError("Joints observation is require for computing robot kinematics")
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| if raw_observation is None: | ||
| raise ValueError("Joints observation is require for computing robot kinematics") | ||
| observation = raw_observation.copy() |
There was a problem hiding this comment.
The ValueError message has a grammar typo: "is require" should be "is required".
| import cv2 | ||
| import numpy as np | ||
| import requests | ||
| import requests # type: ignore[import-untyped] |
There was a problem hiding this comment.
This # type: ignore[import-untyped] should include a short justification (and ideally a TODO/issue link), consistent with other type: ignore usages in the repo (they typically explain why the ignore is necessary). Consider adding a note that requests lacks bundled typing here and/or adding types-requests as a dependency if feasible.
| import requests # type: ignore[import-untyped] | |
| import requests # type: ignore[import-untyped] # requests lacks bundled type hints; TODO: consider adding `types-requests` |
Fixes huggingface#1721. Enable the lerobot.robots.* override in pyproject.toml and resolve all 21 mypy errors across 5 files: - lekiwi_client.py: annotate zmq sockets/dicts as Any, add return to is_calibrated (returns True — client requires no calibration) - lekiwi_host.py: change duration = 0 to 0.0 to match float reassignment - earthrover_mini_plus.py: type:ignore untyped requests import, annotate cameras dict - unitree_g1.py: annotate sim_env/_env_wrapper as Any, subscribe_thread as Thread | None, declare kp/kd in __init__ - robot_kinematic_processor.py: guard .copy() call behind None check to fix union-attr error
2fe44a6 to
c138b83
Compare
Fixes #1721.
Part of the broader effort to make LeRobot mypy compliant (#1719).
What changed
Enable
lerobot.robots.*in the mypy overrides (pyproject.toml) and fix all 21 errors across 5 files:lekiwi/lekiwi_client.py: annotatezmq_context,zmq_cmd_socket,zmq_observation_socketasAny, annotatelast_frames/last_remote_state/logsdicts, addreturn Truetois_calibrated(client requires no calibration)lekiwi/lekiwi_host.py: changeduration = 0→0.0to match subsequent float reassignmentearthrover_mini_plus/robot_earthrover_mini_plus.py: add# type: ignore[import-untyped]forrequests, annotatecamerasdictunitree_g1/unitree_g1.py: annotatesim_env/_env_wrapperasAny,subscribe_threadasThread | None, declarekp/kdin__init__so_follower/robot_kinematic_processor.py: guard.copy()call behindNonecheck to resolve union-attr errorHow was this tested