-
Notifications
You must be signed in to change notification settings - Fork 233
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Include py.typed in a package #936
Comments
I tried adding
I have a file called |
Thank you the response!
This is because mypy uses Here is the document: The easiest way to try $ PYTHONUSERBASE=/opt/ros/foxy mypy foo.py
foo.py:3: note: Revealed type is "types.ModuleType"
foo.py:4: note: Revealed type is "def (*, args: Union[builtins.list[builtins.str], None] =, context: Union[rclpy.context.Context, None] =)"
foo.py:6: error: Module has no attribute "foo"
foo.py:7: error: Unexpected keyword argument "foo" for "init"
/opt/ros/foxy/lib/python3.8/site-packages/rclpy/__init__.py:62: note: "init" defined here
Found 2 errors in 1 file (checked 1 source file) If you use python in a virtualenv, the above method may not work since So, general solution for ROS packages might be creating a $ echo "/opt/ros/foxy/lib/python3.8/site-packages" > $(python -c "import site; print(site.getsitepackages()[0])")/ros.pth
$ mypy foo.py |
Thanks for the clarification @bonprosoft ! Would you be willing to open a PR to fix this in rclpy ? If you tag me as a reviewer I could take a look at it. |
Of course! I've created a PR #946. Could you please take a look? |
Also, I have a question related to the type annotations.
Just FYI: I think the following feature request is also good to have and I am ready to contribute. |
Feature request
Feature description
I use mypy, one of the most famous static type checkers in Python, to check my Python code depending on rclpy.
However, mypy won't use the type annotation of
rclpy
, since mypy only uses the type annotation of packages that are marked as PEP561-compatible (i.e. Packages that havepy.typed
inside).Therefore, I can't check the code like:
Would it be possible to include py.typed in
rclpy
package? (I am happy to work on this task!)Implementation considerations
py.typed
underrclpy
directoryrclpy
usesament_python_install_package
macro, and the macro just copies the directory tree into the install directory:https://github.com/ament/ament_cmake/blob/b84cf9e6f2a61d8f9fc5a90c02dc2b5cb63e7f76/ament_cmake_python/cmake/ament_python_install_package.cmake#L181-L186
py.typed
file is common in Python (e.g. numpy)CMakeLists.txt
:The text was updated successfully, but these errors were encountered: