Skip to content
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

Message field name same as python reserved keyword causes syntax error when importing generated message #95

Closed
ErikOrjehag opened this issue Dec 3, 2019 · 3 comments
Labels
bug Something isn't working duplicate This issue or pull request already exists

Comments

@ErikOrjehag
Copy link

ErikOrjehag commented Dec 3, 2019

Bug report

Required Info:

  • Operating System:
    • Ubuntu 18.04
  • Installation type:
    • binaries
  • Version or commit hash:
    • dashing
  • DDS implementation:
    • Fast-RTPS
  • Client library (if applicable):
    • rclpy

Steps to reproduce issue

msg-file with the following contents

geometry_msgs/Point from
geometry_msgs/Point to

Expected behavior

Import message containing field named "from".

Actual behavior

Gets python runtime error:

  File "/opt/dredgebot_ws/install/dredgebot_behaviours/lib/python3.6/site-packages/dredgebot_behaviours/actions/make_coverage_plan.py", line 22, in <module>
    from dredgebot_msgs.msg import LineSegment
  File "/opt/dredgebot_ws/install/dredgebot_msgs/lib/python3.6/site-packages/dredgebot_msgs/msg/__init__.py", line 1, in <module>
    from dredgebot_msgs.msg._line_segment import LineSegment  # noqa: F401
  File "/opt/dredgebot_ws/install/dredgebot_msgs/lib/python3.6/site-packages/dredgebot_msgs/msg/_line_segment.py", line 82
    self.from = kwargs.get('from', Point())
            ^
SyntaxError: invalid syntax

Additional information

The message file is built using colcon without issues but when the message is imported in python we get an runtime error as described above. We suspect that the keyword "from" is a reserved symbol in python which results in a "SyntaxError". Changing the name "from"--->"start" in the msg-file fixes the problem. We suspect that this is a problem with all reserved keywords in python such as "for", "in", "is" etc but have not tried.

@dirk-thomas dirk-thomas added bug Something isn't working duplicate This issue or pull request already exists labels Dec 3, 2019
@dirk-thomas
Copy link
Member

Until a language specific name mangling is implemented to avoid keywords as described in ros2/design#172 your only option is to avoid using keywords in message definitions.

@samiamlabs
Copy link
Contributor

A warning when building/generating the messages until that is implemented would be nice though. I don't know how common it is to use reserved keywords as filelds but it can be a bit tricky to understad the cause of this bug based on the runtime error messages.

@dirk-thomas
Copy link
Member

A warning when building/generating the messages until that is implemented would be nice though.

That would indeed be nice (but probably also require most of the complexity an actual solution will require). Any pull requests towards this would be more than welcome.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working duplicate This issue or pull request already exists
Projects
None yet
Development

No branches or pull requests

3 participants