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

Add type hints to tf2_ros_py code(#275) #315

Merged
merged 50 commits into from
Sep 10, 2020

Conversation

surfertas
Copy link
Contributor

  1. Added type hints to member functions in tf2_ros_py.
  2. Removed redundant :rtypes annotations from docstring.
  3. Used TypeVar() to define types for LookupTransformGoal and LookupTransformResult.

@surfertas surfertas changed the title Add type hints to tf2_ros_py code(#275) Add type hints to tf2_ros_py code(https://github.com/ros2/geometry2/issues/275) Sep 2, 2020
@surfertas surfertas changed the title Add type hints to tf2_ros_py code(https://github.com/ros2/geometry2/issues/275) Add type hints to tf2_ros_py code([https://github.com/ros2/geometry2/issues/275]) Sep 2, 2020
@surfertas surfertas changed the title Add type hints to tf2_ros_py code([https://github.com/ros2/geometry2/issues/275]) Add type hints to tf2_ros_py code(#275) Sep 2, 2020
@surfertas surfertas changed the title Add type hints to tf2_ros_py code(#275) Add type hints to tf2_ros_py code( #275 ) Sep 2, 2020
@surfertas surfertas changed the title Add type hints to tf2_ros_py code( #275 ) Add type hints to tf2_ros_py code(#275) Sep 2, 2020
@surfertas
Copy link
Contributor Author

@clalancette Hi, can you take a look at the PR for adding to type hints to buffer_client.py. If all good, I will convert the other files in tf2_ros_py and create a commit for each file.

Copy link
Contributor

@clalancette clalancette left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks generally good to me, so I'd encourage you to continue on and do the rest of the files as well. I wouldn't bother doing a separate commit per-file; we are probably going to squash-merge it at the end anyway. Thanks for the work so far!

tf2_ros_py/tf2_ros/buffer_client.py Show resolved Hide resolved
@surfertas
Copy link
Contributor Author

surfertas commented Sep 5, 2020

@clalancette @sloretz This is ready for review.
Please note in buffer_interface.py, I have handled object_stamped accepting PyKDL objects and stamped messages by defining a TransformableObject type.

def transform(self, object_stamped, target_frame, timeout=Duration(), new_type = None):

Separately:

  1. The constructor for StaticTransformBroadcaster and TransformListener both have qos as an Optional[Union[QoSProfile, int]] type and handle None while TransformBroadcaster has qos not as an Optional and does not handle the None case and does not raise a type error if None is passed inadvertently. Should this be handled?

  2. Should time be changed to time.to_msg() constistent with lookup_transform_full() and the signature?

    goal.source_time = time

If yes, I will create a new PR for 1 & 2 and fix the tests if required.

@surfertas surfertas marked this pull request as ready for review September 5, 2020 16:08
@clalancette
Copy link
Contributor

@surfertas Thanks for the work so far. This PR a little hard to review at the moment because it contains changes from other PRs as well. If you rebase this onto the latest ros2 branch, it will have just the changes from you. Then I'll take a look at answering your other questions. Thanks.

@surfertas surfertas changed the base branch from ros2 to foxy September 8, 2020 14:07
@surfertas surfertas changed the base branch from foxy to ros2 September 8, 2020 14:07
@surfertas
Copy link
Contributor Author

@clalancette Apologies and no problem. You should now only see the changes from me. Thank you.

Copy link
Contributor

@clalancette clalancette left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've got a lot of comments inline, but they are all easy to fix and most of them are of the same type. So it should be pretty easy to fix them.

To comment on your other questions:

The constructor for StaticTransformBroadcaster and TransformListener both have qos as an Optional[Union[QoSProfile, int]] type and handle None while TransformBroadcaster has qos not as an Optional and does not handle the None case and does not raise a type error if None is passed inadvertently. Should this be handled?

Yeah, it should be handled. I'd change the TransformBroadcaster to take a None by default, and then have the code construct the proper QoS object if it is None. That makes it similar to the other two.

Should time be changed to time.to_msg() constistent with lookup_transform_full() and the signature?

Sorry, I don't understand this question. Can you expand on it a little more?

tf2_ros_py/tf2_ros/buffer.py Outdated Show resolved Hide resolved
tf2_ros_py/tf2_ros/buffer.py Outdated Show resolved Hide resolved
tf2_ros_py/tf2_ros/buffer.py Outdated Show resolved Hide resolved
tf2_ros_py/tf2_ros/buffer.py Outdated Show resolved Hide resolved
tf2_ros_py/tf2_ros/buffer.py Outdated Show resolved Hide resolved
tf2_ros_py/tf2_ros/buffer_interface.py Outdated Show resolved Hide resolved
tf2_ros_py/tf2_ros/buffer_interface.py Outdated Show resolved Hide resolved
tf2_ros_py/tf2_ros/buffer_interface.py Outdated Show resolved Hide resolved
tf2_ros_py/tf2_ros/buffer_interface.py Outdated Show resolved Hide resolved
tf2_ros_py/tf2_ros/buffer_interface.py Outdated Show resolved Hide resolved
surfertas and others added 16 commits September 9, 2020 21:58
Co-authored-by: Chris Lalancette <clalancette@gmail.com>
Co-authored-by: Chris Lalancette <clalancette@gmail.com>
Co-authored-by: Chris Lalancette <clalancette@gmail.com>
Co-authored-by: Chris Lalancette <clalancette@gmail.com>
Co-authored-by: Chris Lalancette <clalancette@gmail.com>
Co-authored-by: Chris Lalancette <clalancette@gmail.com>
Co-authored-by: Chris Lalancette <clalancette@gmail.com>
Co-authored-by: Chris Lalancette <clalancette@gmail.com>
Co-authored-by: Chris Lalancette <clalancette@gmail.com>
Co-authored-by: Chris Lalancette <clalancette@gmail.com>
Co-authored-by: Chris Lalancette <clalancette@gmail.com>
Co-authored-by: Chris Lalancette <clalancette@gmail.com>
Co-authored-by: Chris Lalancette <clalancette@gmail.com>
Co-authored-by: Chris Lalancette <clalancette@gmail.com>
Co-authored-by: Chris Lalancette <clalancette@gmail.com>
Co-authored-by: Chris Lalancette <clalancette@gmail.com>
Copy link
Contributor

@clalancette clalancette left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Overall, I think this looks great. Thanks for taking this on @surfertas . There are 3 open items here:

  1. We still don't have a resolution on kwargs for set_transform.
  2. We should fix TransformBroadcaster to have a None qos by default, and construct the object inside of the method (like we do with StaticTransformBroadcaster and TransformListener.
  3. We need to fix up lookup_transform to take the right type in.

However, all of these can be left as follow-up tasks. @surfertas could you please open up issues for all 3 of the above items? Once that is done, I'm happy to approve and run CI on this.

@surfertas
Copy link
Contributor Author

@clalancette three separate issues created.

Separately, are there any plans to integrate stubs? Ultimately, will allow users of the library to type check their code.

@clalancette
Copy link
Contributor

@clalancette three separate issues created.

Fantastic, thanks.

Separately, are there any plans to integrate stubs? Ultimately, will allow users of the library to type check their code.

I don't think we've considered it.

Copy link
Contributor

@clalancette clalancette left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good to me, thanks for all of the work here. I'll run CI on it next.

@clalancette
Copy link
Contributor

CI:

  • Linux Build Status
  • Linux-aarch64 Build Status
  • macOS Build Status
  • Windows Build Status

@clalancette
Copy link
Contributor

@surfertas Tests are failing, probably because you need a <test_depend>sensor_msgs</test_depend> in the package.xml

@surfertas
Copy link
Contributor Author

@surfertas Tests are failing, probably because you need a <test_depend>sensor_msgs</test_depend> in the package.xml

@clalancette Has been added.

@clalancette
Copy link
Contributor

@clalancette Has been added.

Thanks. Here's another CI try:

  • Linux Build Status
  • Linux-aarch64 Build Status
  • macOS Build Status
  • Windows Build Status

@clalancette
Copy link
Contributor

Looks happy, I'm going to go ahead and merge this. Thanks again for the contribution.

@clalancette clalancette merged commit d7276d5 into ros2:ros2 Sep 10, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants