Skip to content

fix(mypy): update pyproject.toml to pass ament_mypy on rolling (#5830)#6105

Open
redddddyyyyy wants to merge 1 commit intoros-navigation:mainfrom
redddddyyyyy:fix/ament-mypy-pyproject
Open

fix(mypy): update pyproject.toml to pass ament_mypy on rolling (#5830)#6105
redddddyyyyy wants to merge 1 commit intoros-navigation:mainfrom
redddddyyyyy:fix/ament-mypy-pyproject

Conversation

@redddddyyyyy
Copy link
Copy Markdown
Contributor

Problem

The ament_mypy pre-commit check fails in fresh ros:rolling environments after apt upgrade (issue #5830). Newer mypy (1.9.0 on Ubuntu Noble) introduced [import-untyped] as a distinct error code that fires when a package is installed but has no py.typed marker or type stubs. This affects all ROS message packages (nav2_msgs, geometry_msgs, action_msgs, etc.) and launch_ros, causing ament_mypy to fail on any Python file that imports them.

PR #5959 temporarily commented out ament_mypy as a workaround. This PR provides the proper fix.

Changes (tools/pyproject.toml)

  • disable_error_code = ["import-untyped"] — directly silences the new error code for packages that are installed but lack type stubs; these cannot be fixed without adding py.typed markers upstream in each ROS package
  • namespace_packages = true — required for mypy to correctly resolve ROS namespace packages
  • python_version = "3.10" — explicit target version for consistent behavior across environments
  • warn_unused_ignores = false — with some ROS packages treated as Any, existing # type: ignore comments in files like robot_navigator.py become stale; disabling this avoids unnecessary churn in source files
  • disallow_subclassing_any = false — nav2 nodes subclass rclpy.node.Node; on environments where rclpy has no stubs, Node is typed as Any and strict mode rejects subclassing it
  • Added rclpy.* and launch_ros.* to the ignore_missing_imports overrides

Testing

Verified locally with ament_mypy --config tools/pyproject.toml on representative Python files including nav2_simple_commander/robot_navigator.py and the benchmarking tools — all pass with exit code 0.

Fixes #5830

@redddddyyyyy redddddyyyyy force-pushed the fix/ament-mypy-pyproject branch from 0e34bf3 to 29e1b0b Compare April 25, 2026 15:58
Newer mypy versions (introduced in rolling after apt upgrade) emit
[import-untyped] errors for installed ROS packages that lack py.typed
markers (rclpy, launch_ros, and all nav2/ROS message packages).
This caused the ament_mypy pre-commit hook to fail (issue ros-navigation#5830).

Changes to tools/pyproject.toml:
- namespace_packages = true: required for mypy to correctly resolve
  ROS namespace packages
- python_version = "3.10": explicit target for consistent behavior
- disable_error_code = ["import-untyped"]: suppress errors for packages
  that are installed but lack type stubs (all ROS packages); these
  cannot be fixed without adding py.typed markers upstream
- warn_unused_ignores = false: with rclpy/launch_ros treated as Any,
  some existing # type: ignore comments become stale; disabling this
  avoids churn in source files that rely on rclpy
- disallow_subclassing_any = false: rclpy.Node is Any since rclpy has
  no stubs; nav2 nodes subclass it, which strict mode otherwise rejects
- Add rclpy.* and launch_ros.* to ignore_missing_imports overrides

Fixes ros-navigation#5830

Signed-off-by: Rajeev <rajeevreddy1009@gmail.com>
@redddddyyyyy redddddyyyyy force-pushed the fix/ament-mypy-pyproject branch from 29e1b0b to 6910626 Compare April 25, 2026 16:00
Copy link
Copy Markdown
Collaborator

@mini-1235 mini-1235 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am not sure if this really fixes this issue, when I test locally, I am still seeing a large number of errors. If you are interested in taking this over, I would recommend reviewing the discussion here: #5830 (comment) and #5837.

The tldr is that, at a minimum, the PR should update the CI so it correctly reflects what users encounter locally when running mypy. I already have a draft PR that addresses this, although it still needs some cleanup. However, progress has been blocked for months due to upstream repository issues and the pending rolling sync, which as far as I know, is still unresolved.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

ament_mypy pre-commit fails on rolling?

2 participants