Hello everyone,
I have recently started to work on some small, some big Python projects that make use of the ROS client libraries (e.g. rclpy, launch, …). When I opened the files I was very excited to see that type annotations had been added to them! However, I quickly realized that it is very hard to properly typecheck a Python package in the current state of things:
- Most packages do not export a
py.typed
file, so mypy interprets them as untyped - A lot of those type annotations are not checked in CI, so they contain errors
- Generated messages do not contain type annotations
A number of projects, PRs and issues have been created to work around these issues:
- Type checking with mypy · Issue #676 · ros2/launch · GitHub
- Better typings · Issue #976 · ros2/rclpy · GitHub
- Add py.typed to package by bonprosoft · Pull Request #946 · ros2/rclpy · GitHub
- Python type annotation · Issue #157 · ros2/rosidl_python · GitHub
Unfortunately, most of those haven’t seen very much follow-up. I would personally love to improve this situation, but I wanted to get some more opinions from the community.
I am also saddened to see that the quality guide does not make a single mention to Python. Since some critical parts of the ROS2 ecosystem (notably launch system) are written in Python, I think it’s a regrettable omission.
Cheers,
Hervé