ros2 / launch_ros

Tools for launching ROS nodes and for writing tests involving ROS nodes.
Apache License 2.0
58 stars 72 forks source link

Create py.typed to mark this library as typed #379

Closed ottojo closed 1 year ago

ottojo commented 1 year ago

This marker file informs type checkers of downstream libraries that launch_ros is typed. In my use case, this enables using the strict typechecking mode in pyright for a downstream project using launch_ros

This was done for rclpy in https://github.com/ros2/rclpy/pull/946

ottojo commented 1 year ago

I'm not quite sure how that caused the failed test in the Rpr__launch_ros__ubuntu_jammy_amd64 CI, that might be unrelated?

Apropos CI: In the linked rclpy PR there is some discussion on testing. Pyright can test libraries for type correctness, but this test currently fails for launch_ros:

pyright --verifytypes launch_ros --ignoreexternal

Symbols exported by "launch_ros": 265
  With known type: 148
  With ambiguous type: 5
  With unknown type: 112
    (Ignoring unknown types imported from other packages)
  Functions without docstring: 13
  Functions without default param: 0
  Classes without docstring: 0

Other symbols referenced but not exported by "launch_ros": 0
  With known type: 0
  With ambiguous type: 0
  With unknown type: 0

Type completeness score: 55.8%

It does however also fail for rclpy:

pyright --verifytypes rclpy --ignoreexternal

[...]

Symbols exported by "rclpy": 827
  With known type: 228
  With ambiguous type: 13
  With unknown type: 586
    (Ignoring unknown types imported from other packages)
  Functions without docstring: 118
  Functions without default param: 0
  Classes without docstring: 27

Other symbols referenced but not exported by "rclpy": 19
  With known type: 6
  With ambiguous type: 0
  With unknown type: 13

Type completeness score: 27.6%

I think it still makes sense to mark this as "supposed to by typed" (if this is the intention, i assume this based on the large amount of type hints), it works well for rclpy.

edit: for reference: the pyright documentation for libraries: https://microsoft.github.io/pyright/#/typed-libraries?id=typing-guidance-for-python-libraries

clalancette commented 1 year ago

I'm not quite sure how that caused the failed test in the Rpr__launch_ros__ubuntu_jammy_amd64 CI, that might be unrelated?

Yeah, it's unrelated. It should be fixed by #377

clalancette commented 1 year ago

CI:

clalancette commented 1 year ago

New CI:

clalancette commented 1 year ago

Looks good, thanks for iterating!