fix(mypy): update pyproject.toml to pass ament_mypy on rolling (#5830)#6105
Open
redddddyyyyy wants to merge 1 commit intoros-navigation:mainfrom
Open
fix(mypy): update pyproject.toml to pass ament_mypy on rolling (#5830)#6105redddddyyyyy wants to merge 1 commit intoros-navigation:mainfrom
redddddyyyyy wants to merge 1 commit intoros-navigation:mainfrom
Conversation
0e34bf3 to
29e1b0b
Compare
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>
29e1b0b to
6910626
Compare
mini-1235
requested changes
Apr 27, 2026
Collaborator
mini-1235
left a comment
There was a problem hiding this comment.
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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
The
ament_mypypre-commit check fails in freshros:rollingenvironments afterapt 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 nopy.typedmarker or type stubs. This affects all ROS message packages (nav2_msgs,geometry_msgs,action_msgs, etc.) andlaunch_ros, causing ament_mypy to fail on any Python file that imports them.PR #5959 temporarily commented out
ament_mypyas 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 addingpy.typedmarkers upstream in each ROS packagenamespace_packages = true— required for mypy to correctly resolve ROS namespace packagespython_version = "3.10"— explicit target version for consistent behavior across environmentswarn_unused_ignores = false— with some ROS packages treated asAny, existing# type: ignorecomments in files likerobot_navigator.pybecome stale; disabling this avoids unnecessary churn in source filesdisallow_subclassing_any = false— nav2 nodes subclassrclpy.node.Node; on environments where rclpy has no stubs,Nodeis typed asAnyand strict mode rejects subclassing itrclpy.*andlaunch_ros.*to theignore_missing_importsoverridesTesting
Verified locally with
ament_mypy --config tools/pyproject.tomlon representative Python files includingnav2_simple_commander/robot_navigator.pyand the benchmarking tools — all pass with exit code 0.Fixes #5830