From a5ca206c4977fbbcf61d7b362e02a96f89749206 Mon Sep 17 00:00:00 2001 From: Huy Date: Sun, 19 Oct 2025 23:35:21 +0200 Subject: [PATCH] chore(mypy-compliant): Ensure the model module passes MyPy type checks (#1782) * feat(mypy-compliant): Ensure the model module passes MyPy type checks * fix * uncomment pyproject.toml for model module * fix * fix --------- Co-authored-by: Adil Zouitine Co-authored-by: Steven Palma --- pyproject.toml | 7 +++---- src/lerobot/model/kinematics.py | 20 ++++++++++++-------- 2 files changed, 15 insertions(+), 12 deletions(-) diff --git a/pyproject.toml b/pyproject.toml index 1a7da48ea..250395035 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -282,7 +282,6 @@ ignore_errors = true [[tool.mypy.overrides]] module = "lerobot.envs.*" -# Enable type checking only for the envs module ignore_errors = false @@ -298,9 +297,9 @@ ignore_errors = false # module = "lerobot.optim.*" # ignore_errors = false -# [[tool.mypy.overrides]] -# module = "lerobot.model.*" -# ignore_errors = false +[[tool.mypy.overrides]] +module = "lerobot.model.*" +ignore_errors = false # [[tool.mypy.overrides]] # module = "lerobot.processor.*" diff --git a/src/lerobot/model/kinematics.py b/src/lerobot/model/kinematics.py index f059b9790..95d3b235c 100644 --- a/src/lerobot/model/kinematics.py +++ b/src/lerobot/model/kinematics.py @@ -22,18 +22,18 @@ class RobotKinematics: self, urdf_path: str, target_frame_name: str = "gripper_frame_link", - joint_names: list[str] = None, + joint_names: list[str] | None = None, ): """ Initialize placo-based kinematics solver. Args: - urdf_path: Path to the robot URDF file - target_frame_name: Name of the end-effector frame in the URDF - joint_names: List of joint names to use for the kinematics solver + urdf_path (str): Path to the robot URDF file + target_frame_name (str): Name of the end-effector frame in the URDF + joint_names (list[str] | None): List of joint names to use for the kinematics solver """ try: - import placo + import placo # type: ignore[import-not-found] # C++ library with Python bindings, no type stubs available. TODO: Create stub file or request upstream typing support. except ImportError as e: raise ImportError( "placo is required for RobotKinematics. " @@ -52,7 +52,7 @@ class RobotKinematics: # Initialize frame task for IK self.tip_frame = self.solver.add_frame_task(self.target_frame_name, np.eye(4)) - def forward_kinematics(self, joint_pos_deg): + def forward_kinematics(self, joint_pos_deg: np.ndarray) -> np.ndarray: """ Compute forward kinematics for given joint configuration given the target frame name in the constructor. @@ -77,8 +77,12 @@ class RobotKinematics: return self.robot.get_T_world_frame(self.target_frame_name) def inverse_kinematics( - self, current_joint_pos, desired_ee_pose, position_weight=1.0, orientation_weight=0.01 - ): + self, + current_joint_pos: np.ndarray, + desired_ee_pose: np.ndarray, + position_weight: float = 1.0, + orientation_weight: float = 0.01, + ) -> np.ndarray: """ Compute inverse kinematics using placo solver.