diff --git a/.github/workflows/ros.yml b/.github/workflows/ros.yml index e665b91..5249bd2 100644 --- a/.github/workflows/ros.yml +++ b/.github/workflows/ros.yml @@ -17,3 +17,14 @@ jobs: run: | source /opt/ros/jazzy/setup.bash colcon build + typecheck: + runs-on: ubuntu-24.04 + steps: + - name: Checkout repository + uses: actions/checkout@v4 + - name: Set up Node + uses: actions/setup-node@v4 + with: + node-version: '22' + - name: pyright (example code is fully annotated) + run: npx --yes pyright -p ros2_tutorial_workspace diff --git a/docs/source/gazebo/custom_nodes.rst b/docs/source/gazebo/custom_nodes.rst index 9f35b33..3fc1bb3 100644 --- a/docs/source/gazebo/custom_nodes.rst +++ b/docs/source/gazebo/custom_nodes.rst @@ -273,7 +273,7 @@ name for :program:`Gazebo` to know which entity to set the pose. This name can b .. literalinclude:: ../../../ros2_tutorial_workspace/src/python_package_that_uses_gazebo/python_package_that_uses_gazebo/send_poses_to_gazebo_node.py :language: python - :lines: 45-64 + :lines: 46-65 :emphasize-lines: 7 The second possibly unfamiliar is the choice of ``rclpy.spin_until_future_complete`` to illustrate calling the service @@ -281,7 +281,7 @@ client only once. .. literalinclude:: ../../../ros2_tutorial_workspace/src/python_package_that_uses_gazebo/python_package_that_uses_gazebo/send_poses_to_gazebo_node.py :language: python - :lines: 67-82 + :lines: 68-83 :emphasize-lines: 11 .. admonition:: Exercises @@ -393,7 +393,7 @@ There is also a simple proportional controller in one dimension. .. literalinclude:: ../../../ros2_tutorial_workspace/src/python_package_that_uses_gazebo/python_package_that_uses_gazebo/control_shape_thrust_node.py :language: python - :lines: 68-71 + :lines: 68-72 Lastly, in the ``timer_callback``, we use the current coordinate value to compute the control action and send it to :program:`Gazebo`. @@ -401,7 +401,7 @@ Lastly, in the ``timer_callback``, we use the current coordinate value to comput .. literalinclude:: ../../../ros2_tutorial_workspace/src/python_package_that_uses_gazebo/python_package_that_uses_gazebo/control_shape_thrust_node.py :language: python :emphasize-lines: 11,13 - :lines: 93-114 + :lines: 94-115 .. admonition:: Exercises diff --git a/ros2_tutorial_workspace/pyrightconfig.json b/ros2_tutorial_workspace/pyrightconfig.json new file mode 100644 index 0000000..7a660dd --- /dev/null +++ b/ros2_tutorial_workspace/pyrightconfig.json @@ -0,0 +1,17 @@ +{ + "include": [ + "src" + ], + "exclude": [ + "**/test/**", + "**/build/**", + "**/install/**", + "**/log/**", + "**/resource/**" + ], + "reportMissingImports": "none", + "reportMissingModuleSource": "none", + "reportMissingParameterType": "error", + "pythonVersion": "3.12", + "stubPath": "stubs" +} diff --git a/ros2_tutorial_workspace/src/python_package_that_uses_gazebo/launch/control_shape_thrust_launch.py b/ros2_tutorial_workspace/src/python_package_that_uses_gazebo/launch/control_shape_thrust_launch.py index 24065ef..c4c9ca3 100644 --- a/ros2_tutorial_workspace/src/python_package_that_uses_gazebo/launch/control_shape_thrust_launch.py +++ b/ros2_tutorial_workspace/src/python_package_that_uses_gazebo/launch/control_shape_thrust_launch.py @@ -4,7 +4,7 @@ from launch_ros.actions import Node -def generate_launch_description(): +def generate_launch_description() -> LaunchDescription: this_package_share_directory = get_package_share_directory('python_package_that_uses_gazebo') diff --git a/ros2_tutorial_workspace/src/python_package_that_uses_gazebo/launch/send_poses_to_gazebo_launch.py b/ros2_tutorial_workspace/src/python_package_that_uses_gazebo/launch/send_poses_to_gazebo_launch.py index a4aceca..1b2aed2 100644 --- a/ros2_tutorial_workspace/src/python_package_that_uses_gazebo/launch/send_poses_to_gazebo_launch.py +++ b/ros2_tutorial_workspace/src/python_package_that_uses_gazebo/launch/send_poses_to_gazebo_launch.py @@ -2,7 +2,7 @@ from launch_ros.actions import Node -def generate_launch_description(): +def generate_launch_description() -> LaunchDescription: node = Node( output='screen', diff --git a/ros2_tutorial_workspace/src/python_package_that_uses_gazebo/launch/send_wrenches_to_gazebo_launch.py b/ros2_tutorial_workspace/src/python_package_that_uses_gazebo/launch/send_wrenches_to_gazebo_launch.py index 6239391..0c26308 100644 --- a/ros2_tutorial_workspace/src/python_package_that_uses_gazebo/launch/send_wrenches_to_gazebo_launch.py +++ b/ros2_tutorial_workspace/src/python_package_that_uses_gazebo/launch/send_wrenches_to_gazebo_launch.py @@ -2,7 +2,7 @@ from launch_ros.actions import Node -def generate_launch_description(): +def generate_launch_description() -> LaunchDescription: node = Node( output='screen', diff --git a/ros2_tutorial_workspace/src/python_package_that_uses_gazebo/python_package_that_uses_gazebo/control_shape_thrust_node.py b/ros2_tutorial_workspace/src/python_package_that_uses_gazebo/python_package_that_uses_gazebo/control_shape_thrust_node.py index c5bd8a0..00c8e0f 100644 --- a/ros2_tutorial_workspace/src/python_package_that_uses_gazebo/python_package_that_uses_gazebo/control_shape_thrust_node.py +++ b/ros2_tutorial_workspace/src/python_package_that_uses_gazebo/python_package_that_uses_gazebo/control_shape_thrust_node.py @@ -34,7 +34,7 @@ class ControlShapeThrustNode(Node): """A ROS2 Node that controls the thrust of a shape in Gazebo. It will apply force based on the position of an entity.""" - def __init__(self): + def __init__(self) -> None: super().__init__('control_shape_thurst_node') # Structured easily to be changed into configurable parameters @@ -65,7 +65,8 @@ def __init__(self): self.timer_period: float = 0.001 self.timer = self.create_timer(self.timer_period, self.timer_callback) - def compute_control_action(self, current, target, proportional_gain:float = 5.0) -> float: + def compute_control_action(self, current: float, target: float, + proportional_gain: float = 5.0) -> float: """A simple proportional controller""" error = current - target return -proportional_gain * error @@ -90,7 +91,7 @@ def send_force_to_gazebo(self, force: tuple[float, float, float] = (0, 0, 0)) -> self.wrench_publisher.publish(ew) - def timer_callback(self): + def timer_callback(self) -> None: """The timer callback will look up the transforms and send the next control action.""" try: @@ -114,7 +115,7 @@ def timer_callback(self): f'Could not get transform from `{self.parent_name}` to `{self.child_name}`: {e}') -def main(args=None): +def main(args: list[str] | None = None) -> None: """ The main function. :param args: Not used directly by the user, but used by ROS2 to configure certain aspects of the Node. diff --git a/ros2_tutorial_workspace/src/python_package_that_uses_gazebo/python_package_that_uses_gazebo/send_poses_to_gazebo_node.py b/ros2_tutorial_workspace/src/python_package_that_uses_gazebo/python_package_that_uses_gazebo/send_poses_to_gazebo_node.py index ff70930..057155a 100644 --- a/ros2_tutorial_workspace/src/python_package_that_uses_gazebo/python_package_that_uses_gazebo/send_poses_to_gazebo_node.py +++ b/ros2_tutorial_workspace/src/python_package_that_uses_gazebo/python_package_that_uses_gazebo/send_poses_to_gazebo_node.py @@ -27,11 +27,12 @@ import rclpy from rclpy.node import Node from rclpy.executors import ExternalShutdownException +from rclpy.task import Future class SendPosesToGazeboNode(Node): """A ROS2 Node that sends poses to Gazebo""" - def __init__(self): + def __init__(self) -> None: super().__init__('send_poses_to_gazebo_node') self.service_client = self.create_client( @@ -42,7 +43,7 @@ def __init__(self): self.get_logger().info(f'service {self.service_client.srv_name} not available, waiting...') - def send_pose_to_gazebo(self): + def send_pose_to_gazebo(self) -> Future[SetEntityPose.Response]: """Sample method sending a pose to and entity in Gazebo.""" request = SetEntityPose.Request() @@ -64,7 +65,7 @@ def send_pose_to_gazebo(self): return self.service_client.call_async(request) -def main(args=None): +def main(args: list[str] | None = None) -> None: """ The main function. :param args: Not used directly by the user, but used by ROS2 to configure certain aspects of the Node. diff --git a/ros2_tutorial_workspace/src/python_package_that_uses_gazebo/python_package_that_uses_gazebo/send_wrenches_to_gazebo_node.py b/ros2_tutorial_workspace/src/python_package_that_uses_gazebo/python_package_that_uses_gazebo/send_wrenches_to_gazebo_node.py index 3cfbddd..1f37e4d 100644 --- a/ros2_tutorial_workspace/src/python_package_that_uses_gazebo/python_package_that_uses_gazebo/send_wrenches_to_gazebo_node.py +++ b/ros2_tutorial_workspace/src/python_package_that_uses_gazebo/python_package_that_uses_gazebo/send_wrenches_to_gazebo_node.py @@ -31,7 +31,7 @@ class SendWrenchesToGazeboNode(Node): """A ROS2 Node that sends wrenches to Gazebo.""" - def __init__(self): + def __init__(self) -> None: super().__init__('send_wrenches_to_gazebo_node') self.publisher = self.create_publisher( @@ -43,7 +43,7 @@ def __init__(self): self.get_logger().info("Waiting for subscriber to be connected...") time.sleep(1) - def send_wrench_to_gazebo(self): + def send_wrench_to_gazebo(self) -> None: """Basic method publishing wrenches to Gazebo.""" ew = EntityWrench() @@ -70,7 +70,7 @@ def send_wrench_to_gazebo(self): self.publisher.publish(ew) -def main(args=None): +def main(args: list[str] | None = None) -> None: """ The main function. :param args: Not used directly by the user, but used by ROS2 to configure certain aspects of the Node. diff --git a/ros2_tutorial_workspace/src/python_package_that_uses_geometry_msgs/python_package_that_uses_geometry_msgs/create_stamped_transforms_node.py b/ros2_tutorial_workspace/src/python_package_that_uses_geometry_msgs/python_package_that_uses_geometry_msgs/create_stamped_transforms_node.py index 922cc89..a1d97bc 100644 --- a/ros2_tutorial_workspace/src/python_package_that_uses_geometry_msgs/python_package_that_uses_geometry_msgs/create_stamped_transforms_node.py +++ b/ros2_tutorial_workspace/src/python_package_that_uses_geometry_msgs/python_package_that_uses_geometry_msgs/create_stamped_transforms_node.py @@ -30,10 +30,10 @@ class CreateStampedTransformsNode(Node): """A ROS2 Node that creates TransformStamped objects.""" - def __init__(self): + def __init__(self) -> None: super().__init__('create_stamped_transforms_node') - def create_and_print_stamped_transform(self): + def create_and_print_stamped_transform(self) -> None: """Basic method showing the creation of TransformStamped objects.""" tfs = TransformStamped() @@ -62,7 +62,7 @@ def create_and_print_stamped_transform(self): f"and rotation:" f" {tfs.transform.rotation}.") -def main(args=None): +def main(args: list[str] | None = None) -> None: """ The main function. :param args: Not used directly by the user, but used by ROS2 to configure certain aspects of the Node. diff --git a/ros2_tutorial_workspace/src/python_package_that_uses_nav2/python_package_that_uses_nav2/nav2_initial_pose_publisher_node.py b/ros2_tutorial_workspace/src/python_package_that_uses_nav2/python_package_that_uses_nav2/nav2_initial_pose_publisher_node.py index aed49af..b8ea803 100644 --- a/ros2_tutorial_workspace/src/python_package_that_uses_nav2/python_package_that_uses_nav2/nav2_initial_pose_publisher_node.py +++ b/ros2_tutorial_workspace/src/python_package_that_uses_nav2/python_package_that_uses_nav2/nav2_initial_pose_publisher_node.py @@ -31,7 +31,7 @@ class Nav2InitialPosePublisherNode(Node): """A ROS2 Node that publishes the initial pose for nav2.""" - def __init__(self): + def __init__(self) -> None: super().__init__('nav2_initial_pose_publisher_node') self._topic = '/initialpose' @@ -48,7 +48,7 @@ def __init__(self): self.get_logger().info(f"Publisher count is {publisher_count}.") time.sleep(1) - def send_initial_pose_with_covariance(self): + def send_initial_pose_with_covariance(self) -> None: """Method to create the PoseWithCovarianceStamped.""" self.get_logger().info(f"Publishing pose to topic: {self._topic}.") @@ -72,7 +72,7 @@ def send_initial_pose_with_covariance(self): self.publisher.publish(pwcs) -def main(args=None): +def main(args: list[str] | None = None) -> None: """ The main function. :param args: Not used directly by the user, but used by ROS2 to configure diff --git a/ros2_tutorial_workspace/src/python_package_that_uses_nav2/python_package_that_uses_nav2/nav2_navigate_to_pose_action_client_node.py b/ros2_tutorial_workspace/src/python_package_that_uses_nav2/python_package_that_uses_nav2/nav2_navigate_to_pose_action_client_node.py index 42d1eb8..7435699 100644 --- a/ros2_tutorial_workspace/src/python_package_that_uses_nav2/python_package_that_uses_nav2/nav2_navigate_to_pose_action_client_node.py +++ b/ros2_tutorial_workspace/src/python_package_that_uses_nav2/python_package_that_uses_nav2/nav2_navigate_to_pose_action_client_node.py @@ -34,13 +34,13 @@ class Nav2NavigateToPoseActionClient(Node): """A ROS2 Node with an Action Client for Nav2NavigateToPoseActionClient.""" - def __init__(self): + def __init__(self) -> None: super().__init__('nav2_navigate_to_pose_action_client') self.action_client = ActionClient(self, NavigateToPose, '/navigate_to_pose') - self.send_goal_future = None # This will be used in `send_goal` - self.get_result_future = None # This will be used in 'goal_response_callback' + self.send_goal_future: Future # This will be used in `send_goal` + self.get_result_future: Future # This will be used in 'goal_response_callback' def send_goal_async(self, desired_pose: Pose, behaviour_tree: str) -> None: goal_msg = NavigateToPose.Goal() @@ -77,7 +77,7 @@ def action_feedback_callback(self, feedback_msg: NavigateToPose.Feedback) -> Non self.get_logger().info(f'Received feedback distance: {feedback.distance_remaining}.') -def main(args=None): +def main(args: list[str] | None = None) -> None: """ The main function. :param args: Not used directly by the user, but used by ROS2 to configure certain aspects of the Node. diff --git a/ros2_tutorial_workspace/src/python_package_that_uses_nottf2/python_package_that_uses_nottf2/operations_showcase.py b/ros2_tutorial_workspace/src/python_package_that_uses_nottf2/python_package_that_uses_nottf2/operations_showcase.py index 324f37b..2a65931 100644 --- a/ros2_tutorial_workspace/src/python_package_that_uses_nottf2/python_package_that_uses_nottf2/operations_showcase.py +++ b/ros2_tutorial_workspace/src/python_package_that_uses_nottf2/python_package_that_uses_nottf2/operations_showcase.py @@ -25,7 +25,7 @@ from geometry_msgs.msg import Quaternion import marinholab.nottf2 as ntf2 -def main(): +def main() -> None: phi: float = pi r1: Quaternion = ntf2.rx(phi=phi) diff --git a/ros2_tutorial_workspace/src/python_package_that_uses_parameters_and_launch_files/launch/peanut_butter_falcon_quote_publisher_launch.py b/ros2_tutorial_workspace/src/python_package_that_uses_parameters_and_launch_files/launch/peanut_butter_falcon_quote_publisher_launch.py index f83008d..ee4f286 100644 --- a/ros2_tutorial_workspace/src/python_package_that_uses_parameters_and_launch_files/launch/peanut_butter_falcon_quote_publisher_launch.py +++ b/ros2_tutorial_workspace/src/python_package_that_uses_parameters_and_launch_files/launch/peanut_butter_falcon_quote_publisher_launch.py @@ -2,7 +2,7 @@ from launch_ros.actions import Node -def generate_launch_description(): +def generate_launch_description() -> LaunchDescription: return LaunchDescription([ Node( output='screen', diff --git a/ros2_tutorial_workspace/src/python_package_that_uses_parameters_and_launch_files/python_package_that_uses_parameters_and_launch_files/amazing_quote_configurable_publisher_node.py b/ros2_tutorial_workspace/src/python_package_that_uses_parameters_and_launch_files/python_package_that_uses_parameters_and_launch_files/amazing_quote_configurable_publisher_node.py index 0247f60..264706c 100644 --- a/ros2_tutorial_workspace/src/python_package_that_uses_parameters_and_launch_files/python_package_that_uses_parameters_and_launch_files/amazing_quote_configurable_publisher_node.py +++ b/ros2_tutorial_workspace/src/python_package_that_uses_parameters_and_launch_files/python_package_that_uses_parameters_and_launch_files/amazing_quote_configurable_publisher_node.py @@ -30,7 +30,7 @@ class AmazingQuoteConfigurablePublisherNode(Node): """A configurable ROS2 Node that publishes a configurable amazing quote.""" - def __init__(self): + def __init__(self) -> None: super().__init__('amazing_quote_configurable_publisher_node') # Periodically-obtained parameters @@ -52,7 +52,7 @@ def __init__(self): self.incremental_id: int = 0 - def timer_callback(self): + def timer_callback(self) -> None: """Method that is periodically called by the timer.""" quote: str = self.get_parameter('quote').get_parameter_value().string_value @@ -68,7 +68,7 @@ def timer_callback(self): self.incremental_id = self.incremental_id + 1 -def main(args=None): +def main(args: list[str] | None = None) -> None: """ The main function. :param args: Not used directly by the user, but used by ROS2 to configure diff --git a/ros2_tutorial_workspace/src/python_package_that_uses_tf2/python_package_that_uses_tf2/tf2_broadcaster_node.py b/ros2_tutorial_workspace/src/python_package_that_uses_tf2/python_package_that_uses_tf2/tf2_broadcaster_node.py index 2c67572..13025b2 100644 --- a/ros2_tutorial_workspace/src/python_package_that_uses_tf2/python_package_that_uses_tf2/tf2_broadcaster_node.py +++ b/ros2_tutorial_workspace/src/python_package_that_uses_tf2/python_package_that_uses_tf2/tf2_broadcaster_node.py @@ -33,7 +33,7 @@ class TF2BroadcasterNode(Node): """A ROS2 Node that broadcasts a TransformStamped in compliance with `tf2_ros2`.""" - def __init__(self): + def __init__(self) -> None: super().__init__('tf2_broadcaster_node') # Robot name @@ -47,7 +47,7 @@ def __init__(self): self.timer_elapsed_time: float = 0 self.timer = self.create_timer(self.timer_period, self.timer_callback) - def timer_callback(self): + def timer_callback(self) -> None: # We define some parameters of our trajectory. # Let's make the translation be a circle in 2D with radius of 0.2 meters and frequency of 0.1 Hz. # The rotation will be the robot spinning about the z-axis with the same frequency. @@ -84,7 +84,7 @@ def timer_callback(self): self.timer_elapsed_time += self.timer_period -def main(args=None): +def main(args: list[str] | None = None) -> None: """ The main function. :param args: Not used directly by the user, but used by ROS2 to configure certain aspects of the Node. diff --git a/ros2_tutorial_workspace/src/python_package_that_uses_tf2/python_package_that_uses_tf2/tf2_listener_node.py b/ros2_tutorial_workspace/src/python_package_that_uses_tf2/python_package_that_uses_tf2/tf2_listener_node.py index 8b8d2a2..2c5efc8 100644 --- a/ros2_tutorial_workspace/src/python_package_that_uses_tf2/python_package_that_uses_tf2/tf2_listener_node.py +++ b/ros2_tutorial_workspace/src/python_package_that_uses_tf2/python_package_that_uses_tf2/tf2_listener_node.py @@ -30,7 +30,7 @@ class TF2ListenerNode(Node): """A ROS2 Node that listens to the `tf` topic in compliance with `tf2_ros2`.""" - def __init__(self): + def __init__(self) -> None: super().__init__('tf2_listener_node') # Setting up the TransformListener @@ -44,7 +44,7 @@ def __init__(self): self.timer_period: float = 0.1 self.timer = self.create_timer(self.timer_period, self.timer_callback) - def timer_callback(self): + def timer_callback(self) -> None: try: tfs = self.transform_listener_buffer.lookup_transform( @@ -60,7 +60,7 @@ def timer_callback(self): f'Could not get transform from `{self.parent_name}` to `{self.child_name}`: {e}') -def main(args=None): +def main(args: list[str] | None = None) -> None: """ The main function. :param args: Not used directly by the user, but used by ROS2 to configure certain aspects of the Node. diff --git a/ros2_tutorial_workspace/src/python_package_that_uses_the_actions/python_package_that_uses_the_actions/move_straight_in_2d_action_client_node.py b/ros2_tutorial_workspace/src/python_package_that_uses_the_actions/python_package_that_uses_the_actions/move_straight_in_2d_action_client_node.py index 409f5df..956bccb 100644 --- a/ros2_tutorial_workspace/src/python_package_that_uses_the_actions/python_package_that_uses_the_actions/move_straight_in_2d_action_client_node.py +++ b/ros2_tutorial_workspace/src/python_package_that_uses_the_actions/python_package_that_uses_the_actions/move_straight_in_2d_action_client_node.py @@ -34,13 +34,13 @@ class MoveStraightIn2DActionClientNode(Node): """A ROS2 Node with an Action Client for MoveStraightIn2D.""" - def __init__(self): + def __init__(self) -> None: super().__init__('move_straight_in_2d_action_client') self.action_client = ActionClient(self, MoveStraightIn2D, '/move_straight_in_2d') - self.send_goal_future = None # This will be used in `send_goal` - self.get_result_future = None # This will be used in 'goal_response_callback' + self.send_goal_future: Future # This will be used in `send_goal` + self.get_result_future: Future # This will be used in 'goal_response_callback' def send_goal_async(self, desired_position: Point) -> None: goal_msg = MoveStraightIn2D.Goal() @@ -74,7 +74,7 @@ def action_feedback_callback(self, feedback_msg: MoveStraightIn2D.Feedback) -> N self.get_logger().info(f'Received feedback distance: {feedback.distance}.') -def main(args=None): +def main(args: list[str] | None = None) -> None: """ The main function. :param args: Not used directly by the user, but used by ROS2 to configure certain aspects of the Node. diff --git a/ros2_tutorial_workspace/src/python_package_that_uses_the_actions/python_package_that_uses_the_actions/move_straight_in_2d_action_server_node.py b/ros2_tutorial_workspace/src/python_package_that_uses_the_actions/python_package_that_uses_the_actions/move_straight_in_2d_action_server_node.py index 676300d..1cdaabc 100644 --- a/ros2_tutorial_workspace/src/python_package_that_uses_the_actions/python_package_that_uses_the_actions/move_straight_in_2d_action_server_node.py +++ b/ros2_tutorial_workspace/src/python_package_that_uses_the_actions/python_package_that_uses_the_actions/move_straight_in_2d_action_server_node.py @@ -37,7 +37,7 @@ class MoveStraightIn2DActionServerNode(Node): """A ROS2 Node with an Action Server for MoveStraightIn2D.""" - def __init__(self): + def __init__(self) -> None: super().__init__('move_straight_in_2d_action_server') self.current_position = Point() self.MAX_ITERATIONS: int = 100 @@ -116,7 +116,7 @@ def execute_callback(self, goal: ServerGoalHandle) -> MoveStraightIn2D.Result: return result -def main(args=None): +def main(args: list[str] | None = None) -> None: """ The main function. :param args: Not used directly by the user, but used by ROS2 to configure certain aspects of the Node. diff --git a/ros2_tutorial_workspace/src/python_package_that_uses_the_library/python_package_that_uses_the_library/library_user_node.py b/ros2_tutorial_workspace/src/python_package_that_uses_the_library/python_package_that_uses_the_library/library_user_node.py index 915f108..89bbdef 100644 --- a/ros2_tutorial_workspace/src/python_package_that_uses_the_library/python_package_that_uses_the_library/library_user_node.py +++ b/ros2_tutorial_workspace/src/python_package_that_uses_the_library/python_package_that_uses_the_library/library_user_node.py @@ -33,12 +33,12 @@ class LibraryUser(Node): """A ROS2 Node that prints to the console periodically.""" - def __init__(self): + def __init__(self) -> None: super().__init__('library_user') timer_period: float = 0.5 self.timer = self.create_timer(timer_period, self.timer_callback) - def timer_callback(self): + def timer_callback(self) -> None: """ Method that is periodically called by the timer. Prints out the result of sample_function_for_square_of_sum of two random numbers, @@ -56,7 +56,7 @@ def timer_callback(self): f'returned {sample_class_with_random_name.get_name()}.') -def main(args=None): +def main(args: list[str] | None = None) -> None: """ The main function. :param args: Not used directly by the user, but used by ROS2 to configure diff --git a/ros2_tutorial_workspace/src/python_package_that_uses_the_messages/python_package_that_uses_the_messages/amazing_quote_publisher_node.py b/ros2_tutorial_workspace/src/python_package_that_uses_the_messages/python_package_that_uses_the_messages/amazing_quote_publisher_node.py index 5b15f65..1fde6ac 100644 --- a/ros2_tutorial_workspace/src/python_package_that_uses_the_messages/python_package_that_uses_the_messages/amazing_quote_publisher_node.py +++ b/ros2_tutorial_workspace/src/python_package_that_uses_the_messages/python_package_that_uses_the_messages/amazing_quote_publisher_node.py @@ -30,7 +30,7 @@ class AmazingQuotePublisherNode(Node): """A ROS2 Node that publishes an amazing quote.""" - def __init__(self): + def __init__(self) -> None: super().__init__('amazing_quote_publisher_node') self.amazing_quote_publisher = self.create_publisher( @@ -43,7 +43,7 @@ def __init__(self): self.incremental_id: int = 0 - def timer_callback(self): + def timer_callback(self) -> None: """Method that is periodically called by the timer.""" amazing_quote = AmazingQuote() @@ -56,7 +56,7 @@ def timer_callback(self): self.incremental_id = self.incremental_id + 1 -def main(args=None): +def main(args: list[str] | None = None) -> None: """ The main function. :param args: Not used directly by the user, but used by ROS2 to configure diff --git a/ros2_tutorial_workspace/src/python_package_that_uses_the_messages/python_package_that_uses_the_messages/amazing_quote_subscriber_node.py b/ros2_tutorial_workspace/src/python_package_that_uses_the_messages/python_package_that_uses_the_messages/amazing_quote_subscriber_node.py index 380a19e..1ab5bde 100644 --- a/ros2_tutorial_workspace/src/python_package_that_uses_the_messages/python_package_that_uses_the_messages/amazing_quote_subscriber_node.py +++ b/ros2_tutorial_workspace/src/python_package_that_uses_the_messages/python_package_that_uses_the_messages/amazing_quote_subscriber_node.py @@ -30,7 +30,7 @@ class AmazingQuoteSubscriberNode(Node): """A ROS2 Node that receives and AmazingQuote and prints out its info.""" - def __init__(self): + def __init__(self) -> None: super().__init__('amazing_quote_subscriber_node') self.amazing_quote_subscriber = self.create_subscription( msg_type=AmazingQuote, @@ -38,7 +38,7 @@ def __init__(self): callback=self.amazing_quote_subscriber_callback, qos_profile=1) - def amazing_quote_subscriber_callback(self, msg: AmazingQuote): + def amazing_quote_subscriber_callback(self, msg: AmazingQuote) -> None: """Method that is called when a new msg is received by the node.""" self.get_logger().info(f""" @@ -55,7 +55,7 @@ def amazing_quote_subscriber_callback(self, msg: AmazingQuote): """) -def main(args=None): +def main(args: list[str] | None = None) -> None: """ The main function. :param args: Not used directly by the user, but used by ROS2 to configure diff --git a/ros2_tutorial_workspace/src/python_package_that_uses_the_services/python_package_that_uses_the_services/add_points_service_client_introspection_node.py b/ros2_tutorial_workspace/src/python_package_that_uses_the_services/python_package_that_uses_the_services/add_points_service_client_introspection_node.py index 5a25903..e69513e 100644 --- a/ros2_tutorial_workspace/src/python_package_that_uses_the_services/python_package_that_uses_the_services/add_points_service_client_introspection_node.py +++ b/ros2_tutorial_workspace/src/python_package_that_uses_the_services/python_package_that_uses_the_services/add_points_service_client_introspection_node.py @@ -31,7 +31,7 @@ class AddPointsServiceClientIntrospectionNode(AddPointsServiceClientNode): """A ROS2 Node that enables introspection on its service client.""" - def __init__(self): + def __init__(self) -> None: super().__init__() # https://github.com/ros2/demos/blob/rolling/demo_nodes_py/demo_nodes_py/services/introspection.py @@ -40,7 +40,7 @@ def __init__(self): service_event_qos_profile=qos_profile_system_default, introspection_state=ServiceIntrospectionState.CONTENTS) -def main(args=None): +def main(args: list[str] | None = None) -> None: """ The main function. :param args: Not used directly by the user, but used by ROS2 to configure diff --git a/ros2_tutorial_workspace/src/python_package_that_uses_the_services/python_package_that_uses_the_services/add_points_service_client_just_once_node.py b/ros2_tutorial_workspace/src/python_package_that_uses_the_services/python_package_that_uses_the_services/add_points_service_client_just_once_node.py index 07bb3eb..afea355 100644 --- a/ros2_tutorial_workspace/src/python_package_that_uses_the_services/python_package_that_uses_the_services/add_points_service_client_just_once_node.py +++ b/ros2_tutorial_workspace/src/python_package_that_uses_the_services/python_package_that_uses_the_services/add_points_service_client_just_once_node.py @@ -34,7 +34,7 @@ class AddPointsServiceClientJustOnceNode(Node): """A ROS2 Node with a Service Client for AddPoints, just once.""" - def __init__(self): + def __init__(self) -> None: super().__init__('add_points_service_client_just_once') self.service_client = self.create_client( @@ -62,7 +62,7 @@ def __init__(self): self.future = self.service_client.call_async(request) self.future.add_done_callback(self.process_response) - def process_response(self, future: Future): + def process_response(self, future: Future) -> None: """Callback for the future, that will be called when it is done.""" response = future.result() if response is not None: @@ -75,7 +75,7 @@ def process_response(self, future: Future): self.get_logger().info("The response was None.") -def main(args=None): +def main(args: list[str] | None = None) -> None: """ The main function. :param args: Not used directly by the user, but used by ROS2 to configure diff --git a/ros2_tutorial_workspace/src/python_package_that_uses_the_services/python_package_that_uses_the_services/add_points_service_client_node.py b/ros2_tutorial_workspace/src/python_package_that_uses_the_services/python_package_that_uses_the_services/add_points_service_client_node.py index f094704..77fe46c 100644 --- a/ros2_tutorial_workspace/src/python_package_that_uses_the_services/python_package_that_uses_the_services/add_points_service_client_node.py +++ b/ros2_tutorial_workspace/src/python_package_that_uses_the_services/python_package_that_uses_the_services/add_points_service_client_node.py @@ -34,7 +34,7 @@ class AddPointsServiceClientNode(Node): """A ROS2 Node with a Service Client for AddPoints, that call the service periodically.""" - def __init__(self): + def __init__(self) -> None: super().__init__('add_points_service_client') self.service_client = self.create_client( @@ -51,7 +51,7 @@ def __init__(self): timer_period_sec=timer_period, callback=self.timer_callback) - def timer_callback(self): + def timer_callback(self) -> None: """Method that is periodically called by the timer.""" request = AddPoints.Request() @@ -71,7 +71,7 @@ def timer_callback(self): self.future = self.service_client.call_async(request) self.future.add_done_callback(self.process_response) - def process_response(self, future: Future): + def process_response(self, future: Future) -> None: """Callback for the future, that will be called when it is done""" response = future.result() if response is not None: @@ -80,7 +80,7 @@ def process_response(self, future: Future): self.get_logger().info("The response was None.") -def main(args=None): +def main(args: list[str] | None = None) -> None: """ The main function. :param args: Not used directly by the user, but used by ROS2 to configure diff --git a/ros2_tutorial_workspace/src/python_package_that_uses_the_services/python_package_that_uses_the_services/add_points_service_server_introspection_node.py b/ros2_tutorial_workspace/src/python_package_that_uses_the_services/python_package_that_uses_the_services/add_points_service_server_introspection_node.py index b3f0908..9c7aa4e 100644 --- a/ros2_tutorial_workspace/src/python_package_that_uses_the_services/python_package_that_uses_the_services/add_points_service_server_introspection_node.py +++ b/ros2_tutorial_workspace/src/python_package_that_uses_the_services/python_package_that_uses_the_services/add_points_service_server_introspection_node.py @@ -31,7 +31,7 @@ class AddPointsServiceServerIntrospectionNode(AddPointsServiceServerNode): """A ROS2 Node that enables introspection on its service server.""" - def __init__(self): + def __init__(self) -> None: super().__init__() # https://github.com/ros2/demos/blob/rolling/demo_nodes_py/demo_nodes_py/services/introspection.py @@ -40,7 +40,7 @@ def __init__(self): service_event_qos_profile=qos_profile_system_default, introspection_state=ServiceIntrospectionState.CONTENTS) -def main(args=None): +def main(args: list[str] | None = None) -> None: """ The main function. :param args: Not used directly by the user, but used by ROS2 to configure diff --git a/ros2_tutorial_workspace/src/python_package_that_uses_the_services/python_package_that_uses_the_services/add_points_service_server_node.py b/ros2_tutorial_workspace/src/python_package_that_uses_the_services/python_package_that_uses_the_services/add_points_service_server_node.py index 4b1594c..b7d6db2 100644 --- a/ros2_tutorial_workspace/src/python_package_that_uses_the_services/python_package_that_uses_the_services/add_points_service_server_node.py +++ b/ros2_tutorial_workspace/src/python_package_that_uses_the_services/python_package_that_uses_the_services/add_points_service_server_node.py @@ -30,7 +30,7 @@ class AddPointsServiceServerNode(Node): """A ROS2 Node with a Service Server for AddPoints.""" - def __init__(self): + def __init__(self) -> None: super().__init__('add_points_service_server') self.service_server = self.create_service( @@ -55,7 +55,7 @@ def add_points_service_callback(self, return response -def main(args=None): +def main(args: list[str] | None = None) -> None: """ The main function. :param args: Not used directly by the user, but used by ROS2 to configure diff --git a/ros2_tutorial_workspace/src/python_package_with_a_library/python_package_with_a_library/sample_python_library/_sample_class.py b/ros2_tutorial_workspace/src/python_package_with_a_library/python_package_with_a_library/sample_python_library/_sample_class.py index 50825c1..17cb45e 100644 --- a/ros2_tutorial_workspace/src/python_package_with_a_library/python_package_with_a_library/sample_python_library/_sample_class.py +++ b/ros2_tutorial_workspace/src/python_package_with_a_library/python_package_with_a_library/sample_python_library/_sample_class.py @@ -26,7 +26,7 @@ class SampleClass: """A sample class to check how they can be imported by other ROS2 packages.""" - def __init__(self, name: str): + def __init__(self, name: str) -> None: self._name = name def get_name(self) -> str: diff --git a/ros2_tutorial_workspace/src/python_package_with_a_node/python_package_with_a_node/print_forever_node.py b/ros2_tutorial_workspace/src/python_package_with_a_node/python_package_with_a_node/print_forever_node.py index 75530e1..4a95e95 100644 --- a/ros2_tutorial_workspace/src/python_package_with_a_node/python_package_with_a_node/print_forever_node.py +++ b/ros2_tutorial_workspace/src/python_package_with_a_node/python_package_with_a_node/print_forever_node.py @@ -29,19 +29,19 @@ class PrintForever(Node): """A ROS2 Node that prints to the console periodically.""" - def __init__(self): + def __init__(self) -> None: super().__init__('print_forever') timer_period: float = 0.5 self.timer = self.create_timer(timer_period, self.timer_callback) self.print_count: int = 0 - def timer_callback(self): + def timer_callback(self) -> None: """Method that is periodically called by the timer.""" self.get_logger().info(f'Printed {self.print_count} times.') self.print_count = self.print_count + 1 -def main(args=None): +def main(args: list[str] | None = None) -> None: """ The main function. :param args: Not used directly by the user, but used by ROS2 to configure diff --git a/ros2_tutorial_workspace/src/python_package_with_a_node/python_package_with_a_node/sample_python_node.py b/ros2_tutorial_workspace/src/python_package_with_a_node/python_package_with_a_node/sample_python_node.py index 8054eec..c03c398 100644 --- a/ros2_tutorial_workspace/src/python_package_with_a_node/python_package_with_a_node/sample_python_node.py +++ b/ros2_tutorial_workspace/src/python_package_with_a_node/python_package_with_a_node/sample_python_node.py @@ -1,4 +1,4 @@ -def main(): +def main() -> None: print('Hi from python_package_with_a_node.') diff --git a/ros2_tutorial_workspace/stubs/launch/__init__.pyi b/ros2_tutorial_workspace/stubs/launch/__init__.pyi new file mode 100644 index 0000000..03979ee --- /dev/null +++ b/ros2_tutorial_workspace/stubs/launch/__init__.pyi @@ -0,0 +1,4 @@ +from typing import Any + +class LaunchDescription: + def __init__(self, *args: Any, **kwargs: Any) -> None: ... diff --git a/ros2_tutorial_workspace/stubs/launch_ros/__init__.pyi b/ros2_tutorial_workspace/stubs/launch_ros/__init__.pyi new file mode 100644 index 0000000..e69de29 diff --git a/ros2_tutorial_workspace/stubs/launch_ros/actions.pyi b/ros2_tutorial_workspace/stubs/launch_ros/actions.pyi new file mode 100644 index 0000000..1f0368c --- /dev/null +++ b/ros2_tutorial_workspace/stubs/launch_ros/actions.pyi @@ -0,0 +1,4 @@ +from typing import Any + +class Node: + def __init__(self, **kwargs: Any) -> None: ... diff --git a/ros2_tutorial_workspace/stubs/package_with_interfaces/__init__.pyi b/ros2_tutorial_workspace/stubs/package_with_interfaces/__init__.pyi new file mode 100644 index 0000000..e69de29 diff --git a/ros2_tutorial_workspace/stubs/package_with_interfaces/action.pyi b/ros2_tutorial_workspace/stubs/package_with_interfaces/action.pyi new file mode 100644 index 0000000..97fadd8 --- /dev/null +++ b/ros2_tutorial_workspace/stubs/package_with_interfaces/action.pyi @@ -0,0 +1,11 @@ +from typing import Any + +class _GeneratedAction: + def __getattr__(self, name: str) -> Any: ... + def __setattr__(self, name: str, value: Any) -> None: ... + +class MoveStraightIn2D(_GeneratedAction): + class Goal(_GeneratedAction): ... + class Result(_GeneratedAction): ... + class Feedback(_GeneratedAction): ... + class Response(_GeneratedAction): ... diff --git a/ros2_tutorial_workspace/stubs/package_with_interfaces/msg.pyi b/ros2_tutorial_workspace/stubs/package_with_interfaces/msg.pyi new file mode 100644 index 0000000..5bcb6a2 --- /dev/null +++ b/ros2_tutorial_workspace/stubs/package_with_interfaces/msg.pyi @@ -0,0 +1,7 @@ +from typing import Any + +class _GeneratedMsg: + def __getattr__(self, name: str) -> Any: ... + def __setattr__(self, name: str, value: Any) -> None: ... + +class AmazingQuote(_GeneratedMsg): ... diff --git a/ros2_tutorial_workspace/stubs/package_with_interfaces/srv.pyi b/ros2_tutorial_workspace/stubs/package_with_interfaces/srv.pyi new file mode 100644 index 0000000..ba999a6 --- /dev/null +++ b/ros2_tutorial_workspace/stubs/package_with_interfaces/srv.pyi @@ -0,0 +1,9 @@ +from typing import Any + +class _GeneratedSrv: + def __getattr__(self, name: str) -> Any: ... + def __setattr__(self, name: str, value: Any) -> None: ... + +class AddPoints(_GeneratedSrv): + class Request(_GeneratedSrv): ... + class Response(_GeneratedSrv): ...