Repository navigation
Annotate the ROS2-derived attributes and local variables - #59
Merged
Merged
Conversation
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.
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.
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_serverannotated with their rclpy classes (Publisher,Subscription,Timer,Client,Service,ActionClient,ActionServer);self.futurein the two service clients getsrclpy.task.Future, matching thesend_goal_future/get_result_futuredeclarations from Fully annotate the example code and gate it with pyright #57goal_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, notPublisher[AmazingQuote]: rclpy's classes are notGenericin Jazzy, and annotations onself.x: ...targets are evaluated at runtime (PEP 526), so the subscript would raiseTypeError. 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.xmlgains<depend>geometry_msgs</depend>— the thrust controller now imports the transform type, and 5.1 requires declaring imports.literalinclude :lines:ranges in nine pages re-anchored by content (the new imports shift the files by 1-3 lines); oneemphasize-linesset updated for the wrappedActionClientconstructor.Verification:
pyright -p ros2_tutorial_workspace0 errors, linter 0 errors (1 pre-existing warning), flake8 delta is only E501s in the 80-98 range the repo already uses, all filespy_compileclean.