Repository navigation
Fully annotate the example code and gate it with pyright - #57
Merged
Merged
Conversation
The preamble teaches 'Take the (type) hint: Always use type hints' and promises the two simplest forms (argument and return types), but the ROS2 examples drifted away from it: 62 functions across 26 files were missing annotations. All now annotated in the tutorial's own style: - '-> None' everywhere nothing is returned; main() takes 'args: list[str] | None = None'; - subscription/service/action callbacks keep their (already annotated) message parameters and gain return types; compute_control_action() gains float parameters (also fixing the ':float' spacing); - the two action clients declare 'self.send_goal_future: Future' / 'self.get_result_future: Future' instead of '= None', which also removes the type conflict mypy flagged when the futures are assigned; - send_pose_to_gazebo() returns Future[SetEntityPose.Response]; launch files' generate_launch_description() returns LaunchDescription. mypy --disallow-untyped-defs is now clean over the whole workspace; flake8 shows no new violations (net -4).
The re-annotated send_poses_to_gazebo_node.py and control_shape_thrust_node.py grew one line each (rclpy.task import and the wrapped compute_control_action signature); the four excerpt ranges are shifted accordingly.
New typecheck job runs pyright over ros2_tutorial_workspace (reportMissingParameterType error; ROS imports resolved via targeted stubs for the colcon-generated package_with_interfaces message/service / action classes and the launch/launch_ros classes, since those Python bindings are generated at build time). Together with the annotation pass this keeps the examples 'fully annotated' per the preamble rule: pyright guards parameter types and structure, and the mypy --disallow-untyped-defs audit (run in review) guards return types.
This was referenced Oct 28, 2026
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.
What
The preamble teaches "Take the (type) hint: Always use type hints" and promises the two simplest forms (argument and return types), but the ROS2 examples had drifted: 62 functions across 26 files were missing annotations (audited with
mypy --disallow-untyped-defs, now 0).Workspace (
2840e10)All annotated in the tutorial's own style:
-> Noneeverywhere nothing is returned;main()becomesdef main(args: list[str] | None = None) -> None:(the canonical ROS2 entry-point signature, jazzy ships Python 3.12 so| Noneneeds no import)compute_control_action()gainsfloatparameters (also fixing:floatspacing)self.send_goal_future: Future/self.get_result_future: Futureinstead of= None, which also removes the type conflict mypy flagged when the futures are assignedsend_pose_to_gazebo()returnsFuture[SetEntityPose.Response]; launch files'generate_launch_description()returnsLaunchDescriptionflake8vs the base commit shows no new violations (net -4).Docs (
68b51b7)Two gazebo examples grew one line each (
rclpy.taskimport, wrapped controller signature); the fourliteralinclude :lines:excerpt ranges in the custom-nodes page are re-anchored accordingly.CI (
34719eb)New
typecheckjob (no ROS container needed):with a
ros2_tutorial_workspace/pyrightconfig.json(reportMissingParameterType: error, ROS/colcon imports silenced) plus tiny stubs for the classes colcon only generates at build time (package_with_interfacesmsg/srv/action,launch.LaunchDescription,launch_ros.actions.Node). pyright currently reports 0 errors, 0 warnings over the whole workspace.