-
Notifications
You must be signed in to change notification settings - Fork 59
Message named pkg/Duration with field builtin_interfaces/Duration is invalid #257
Copy link
Copy link
Open
Labels
bugSomething isn't workingSomething isn't working
Description
Generated by Generative AI
No response
Operating System:
Linux
ROS version or commit hash:
rolling
RMW implementation (if applicable):
No response
RMW Configuration (if applicable):
No response
Client library (if applicable):
No response
'ros2 doctor --report' output
No response
Steps to reproduce issue
- Create a message package
pkgcontaining a message type namedDurationwith a field of typebuiltin_interfaces/Duration. - Compile the workspace and inspect the generated Python code.
- Run mypy tests and flake8
Expected behavior
Message type pkg/Duration should be valid.
Actual behavior
The generated message Python code is invalid:
27: /root/target_ws/build/stamped_msgs/rosidl_generator_py/stamped_msgs/msg/_duration.py:87:1: F811 redefinition of unused 'Duration' from line 20
27: class Duration(rosidl_pycommon.interface_base_classes.BaseMessage, metaclass=Metaclass_Duration):
27: ^
27:
27: 1 F811 redefinition of unused 'Duration' from line 20
30: /root/target_ws/build/stamped_msgs/rosidl_generator_py/stamped_msgs/msg/_duration.py:87:1: error: Name "Duration" already defined (possibly by an import) [no-redef]
30: /root/target_ws/build/stamped_msgs/rosidl_generator_py/stamped_msgs/msg/_duration.py: note: In member "__eq__" of class "Duration":
30: /root/target_ws/build/stamped_msgs/rosidl_generator_py/stamped_msgs/msg/_duration.py:151:27: error: "Duration" has no attribute "header" [attr-defined]
30: /root/target_ws/build/stamped_msgs/rosidl_generator_py/stamped_msgs/msg/_duration.py:153:25: error: "Duration" has no attribute "data" [attr-defined]
30: Found 3 errors in 1 file (checked 46 source files)
Additional information
Indeed, there are multiple places in the generated code that do:
from a.msg import b
But if the message is named pkg.Duration and the type of one of its fields is builtin_interfaces.Duration, then this import shadows the actual pkg.Duration and the code gets either confused, or even invalid.
I think all usages of from a.msg import b should be replaced by import a.msg; .... a.msg.b in the generated code. This way, the name collisions would not happen.
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
bugSomething isn't workingSomething isn't working