Skip to content

Annotate the ROS2-derived attributes and local variables - #59

Merged
mmmarinho merged 2 commits into
mainfrom
workspace-annotate-ros2-attributes
Oct 28, 2026
Merged

mmmarinho merged 2 commits into
mainfrom
workspace-annotate-ros2-attributes

Conversation

@mmmarinho

Copy link
Copy Markdown
Owner

Follow-up to #57 (functions). This covers the other half of "Take the (type) hint" for the ROS2 objects the examples hand around — the attributes and locals:

  • self.publisher, self.subscription, self.timer, self.service_client, self.service_server, self.action_client, self.action_server annotated with their rclpy classes (Publisher, Subscription, Timer, Client, Service, ActionClient, ActionServer); self.future in the two service clients gets rclpy.task.Future, matching the send_goal_future/get_result_future declarations from Fully annotate the example code and gate it with pyright #57
  • the message/service/action locals are annotated with their generated types: goal_msg: MoveStraightIn2D.Goal, request: AddPoints.Request, feedback_msg: MoveStraightIn2D.Feedback, tfs: TransformStamped, ...

43 sites in 18 files, plus the corresponding imports.

Why bare types

Publisher, not Publisher[AmazingQuote]: rclpy's classes are not Generic in Jazzy, and annotations on self.x: ... targets are evaluated at runtime (PEP 526), so the subscript would raise TypeError. The concrete message type is right there at the call (create_publisher(msg_type=AmazingQuote, ...)), so the annotation states exactly what is knowable.

Other changes

  • python_package_that_uses_gazebo/package.xml gains <depend>geometry_msgs</depend> — the thrust controller now imports the transform type, and 5.1 requires declaring imports.
  • 52 literalinclude :lines: ranges in nine pages re-anchored by content (the new imports shift the files by 1-3 lines); one emphasize-lines set updated for the wrapped ActionClient constructor.

Verification: pyright -p ros2_tutorial_workspace 0 errors, linter 0 errors (1 pre-existing warning), flake8 delta is only E501s in the 80-98 range the repo already uses, all files py_compile clean.

The functions are fully annotated; this finishes the other half of
'Take the (type) hint' for the ROS2 objects the examples hand around:
what does create_publisher() give you, and what is that request object?

- self.publisher/subscription/timer/service_client/service_server/
  action_client/action_server annotated with their rclpy classes
  (Publisher, Subscription, Timer, Client, Service, ActionClient,
  ActionServer, Future);
- message/service/action locals (Goal(), Request(), Feedback(),
  Result(), EntityWrench(), TransformStamped(), ...) annotated with
  their generated types;
- the two service clients' self.future gets rclpy.task.Future,
  matching the send_goal_future/get_result_future declarations in
  the action clients.

Types are deliberately bare (Publisher, not Publisher[AmazingQuote]):
rclpy's classes are not Generic in Jazzy, and annotations on self.*
targets are evaluated at runtime, so the subscript would raise
TypeError. The concrete message type is visible at the call itself
(create_publisher(msg_type=AmazingQuote, ...)), which keeps the
annotation honest and the diff small.

geometry_msgs is now a real import in the gazebo package (the
transform lookup result), so package.xml declares it per 5.1.
The new rclpy imports and one wrapped ActionClient call shifted the
example files by 1-3 lines; the 52 excerpt ranges in nine pages were
re-anchored by content (HEAD block -> new position), including one
emphasize-lines set in action_clients.rst that now highlights the
wrapped constructor and the two future declarations.
@mmmarinho
mmmarinho merged commit a8ad1bd into main Oct 28, 2026
6 checks passed
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.

1 participant