ros2 / rclpy

rclpy (ROS Client Library for Python)
Apache License 2.0
268 stars 221 forks source link

[Feature] Static Type Checking With ament_mypy #1257

Open InvincibleRMC opened 3 months ago

InvincibleRMC commented 3 months ago

Feature request

Feature description

Using ament_mypy to assure future code has proper typing annotations. First and foremost this change would need to wait on many pull requests as there are over 100 mypy errors still remaining on rolling. This change would also likely require any upstream dependencies to adopt ament_mypy to avoid [no-untyped-call] error and other similar errors being raised from a new upstream function being added and called. I bring up this question now so if this feature is desired I can start getting those upstream dependencies checked with ament_mypy earlier to avoid future waiting. For CI time considerations ament_mypy runs in about 2.4s. The benefits of this would be improved code readability, helping catch unexpected edge cases, as well remove the need for downstream dependencies who type check to suppress [no-untyped-call] and other similar errors whenever using rclpy.

Implementation considerations

For implementation currently only ament_mypy exists. The alternative would be perhaps creating an ament_pyright and using that instead for static type checking.

If this is a feature the maintainers are willing to support I will gladly help accomplish this goal. And if anyone else wants to help test with ament_mypy or add type annotations to rclpy or any other ROS2 python file that would be greatly appreciated.

fujitatomoya commented 3 months ago

@InvincibleRMC 1st of all, really appreciate all the contribution you have been and are making for rclpy type check.

we expected that this feature request would come up. i think mostly your consideration describes pretty much everything like dependencies, benefits and concerns so on. (IMO, this should be integrated into CI/CD pipeline, so that we can sustain the type checking.)

i think that this will be better consistent and readable for sure, but that is gonna be the work and a long run. i also would like to hear from more opinion here.

let's keep this open to get more feedback!