Add type hints to minimal publisher rclpy example#439
Open
andrearichichi wants to merge 3 commits intoros2:rollingfrom
Open
Add type hints to minimal publisher rclpy example#439andrearichichi wants to merge 3 commits intoros2:rollingfrom
andrearichichi wants to merge 3 commits intoros2:rollingfrom
Conversation
Signed-off-by: Andrea Richichi <andrea.richichi@studenti.unitn.it>
InvincibleRMC
requested changes
Mar 19, 2026
| def __init__(self) -> None: | ||
| super().__init__('minimal_publisher') | ||
| self.publisher_ = self.create_publisher(String, 'topic', 10) | ||
| self.publisher_: Publisher[String] = self.create_publisher(String, 'topic', 10) |
There was a problem hiding this comment.
Suggested change
| self.publisher_: Publisher[String] = self.create_publisher(String, 'topic', 10) | |
| self.publisher_= self.create_publisher(String, 'topic', 10) |
| # See the License for the specific language governing permissions and | ||
| # limitations under the License. | ||
|
|
||
| from typing import List, Optional |
| self.publisher_: Publisher[String] = self.create_publisher(String, 'topic', 10) | ||
| timer_period = 0.5 # seconds | ||
| self.timer = self.create_timer(timer_period, self.timer_callback) | ||
| self.timer: Timer = self.create_timer(timer_period, self.timer_callback) |
There was a problem hiding this comment.
Suggested change
| self.timer: Timer = self.create_timer(timer_period, self.timer_callback) | |
| self.timer = self.create_timer(timer_period, self.timer_callback) |
| def timer_callback(self): | ||
| msg = String() | ||
| def timer_callback(self) -> None: | ||
| msg: String = String() |
There was a problem hiding this comment.
Suggested change
| msg: String = String() | |
| msg = String() |
Signed-off-by: Andrea Richichi <andrea.richichi@studenti.unitn.it>
InvincibleRMC
requested changes
Mar 20, 2026
InvincibleRMC
left a comment
There was a problem hiding this comment.
You still need type hint on function args like main.
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.
This PR adds Python type hints to the minimal publisher rclpy example.
It annotates function return types and key variables (publisher, timer, and message).
No logic or behavior has been changed.
The diff is intentionally minimal and limited to typing improvements only.