Skip to content

Added test_mypy.py and resolved all regressions in demo_nodes_py (#767)#780

Open
cronenberg64 wants to merge 4 commits intoros2:rollingfrom
cronenberg64:feature/add-mypy-demo-nodes-py
Open

Added test_mypy.py and resolved all regressions in demo_nodes_py (#767)#780
cronenberg64 wants to merge 4 commits intoros2:rollingfrom
cronenberg64:feature/add-mypy-demo-nodes-py

Conversation

@cronenberg64
Copy link

Added test_mypy.py file and resolved all regressions.

Fixes #767

Copilot AI review requested due to automatic review settings March 17, 2026 17:15
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR adds ament_mypy linting to demo_nodes_py and updates the Python demo nodes/tests with type annotations to satisfy strict mypy checks, addressing issue #767.

Changes:

  • Added a new test_mypy.py test and declared ament_mypy as a test dependency.
  • Added/expanded type annotations across multiple demo nodes (topics, services, parameters, logging, events) to resolve mypy regressions.
  • Minor formatting tweaks (e.g., line wrapping) and added shebangs to several Python entrypoint modules.

Reviewed changes

Copilot reviewed 18 out of 18 changed files in this pull request and generated 1 comment.

Show a summary per file
File Description
demo_nodes_py/test/test_pep257.py Adds return type annotation to satisfy stricter typing expectations in tests.
demo_nodes_py/test/test_flake8.py Adds return type annotation to satisfy stricter typing expectations in tests.
demo_nodes_py/test/test_copyright.py Adds return type annotation to satisfy stricter typing expectations in tests.
demo_nodes_py/test/test_mypy.py Introduces mypy linter test for the package.
demo_nodes_py/package.xml Adds ament_mypy as a test_depend.
demo_nodes_py/demo_nodes_py/topics/talker.py Adds shebang and type annotations (incl. timer type).
demo_nodes_py/demo_nodes_py/topics/talker_qos.py Adds shebang and type annotations for QoS usage and timer.
demo_nodes_py/demo_nodes_py/topics/listener.py Adds shebang, type annotations, and wraps subscription call for style.
demo_nodes_py/demo_nodes_py/topics/listener_qos.py Adds shebang and type annotations for QoS usage and callbacks.
demo_nodes_py/demo_nodes_py/topics/listener_serialized.py Adds shebang, callback typing for raw bytes subscription, and adjusts log formatting.
demo_nodes_py/demo_nodes_py/services/introspection.py Adds shebang and type annotations (Timer/Future, callbacks, service handler).
demo_nodes_py/demo_nodes_py/services/add_two_ints_server.py Adds shebang and type annotations for service handler.
demo_nodes_py/demo_nodes_py/services/add_two_ints_client.py Adds shebang and type annotations; refactors result logging for mypy.
demo_nodes_py/demo_nodes_py/services/add_two_ints_client_async.py Adds shebang and type annotations; refactors result logging for mypy.
demo_nodes_py/demo_nodes_py/parameters/set_parameters_callback.py Adds shebang and type annotations for parameter callback hooks.
demo_nodes_py/demo_nodes_py/parameters/async_param_client.py Adds shebang, type annotations, and renames futures/loop vars for clarity and typing.
demo_nodes_py/demo_nodes_py/logging/use_logger_service.py Adds shebang and type annotations; adds a couple targeted mypy ignores for generated message fields.
demo_nodes_py/demo_nodes_py/events/matched_event_detect.py Replaces ... lambdas with None returns and adds typing for callbacks/future helpers.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

You can also share your feedback on Copilot code review. Take the survey.



def test_mypy() -> None:
rc = main()
…des_py (ros2#767)

Resolves ros2#767 by enabling strict type checking.

Key Changes:
- Added strict annotations and return types to 14+ modules to pass mypy --strict.
- Corrected a functional error in matched_event_detect.py where ROS message types were used as type annotations for topic names.
- Added test/test_mypy.py and updated package.xml for ament_mypy support.
- Ensured node scripts maintain correct #!/usr/bin/env python3 shebangs and LF line endings.

Signed-off-by: Jonathan Setiawan <jonathanrustam2@gmail.com>
@cronenberg64 cronenberg64 force-pushed the feature/add-mypy-demo-nodes-py branch from ebdb446 to b639a2d Compare March 17, 2026 19:01
Signed-off-by: Jonathan Setiawan <jonathanrustam2@gmail.com>
@cronenberg64
Copy link
Author

@fujitatomoya @InvincibleRMC
Hello,
I've just addressed all the suggestions you've given me. Thank you very much for the feedback, please check my latest commit if there are any further mistakes, I will address them right away! I look forward to hearing back from you soon.

@ahcorde
Copy link
Contributor

ahcorde commented Mar 18, 2026

Pulls: #780
Gist: https://gist.githubusercontent.com/ahcorde/461a365b20b2d6bd27d954d046a06c37/raw/df131c1c43d52ec2f46e16edc5727abe958fa11c/ros2.repos
BUILD args: --packages-up-to demo_nodes_py
TEST args: --packages-select demo_nodes_py
ROS Distro: rolling
Job: ci_launcher
ci_launcher ran: https://ci.ros2.org/job/ci_launcher/18542

  • Linux Build Status
  • Linux-aarch64 Build Status
  • Linux-rhel Build Status
  • Windows Build Status

Signed-off-by: Jonathan Setiawan <jonathanrustam2@gmail.com>
Signed-off-by: Jonathan Setiawan <jonathanrustam2@gmail.com>
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.

Add ament_mypy to demo_nodes_py

5 participants