Skip to content

Fix time.py and clock.py circular import #860

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

Merged
merged 1 commit into from
Dec 10, 2021
Merged

Conversation

sloretz
Copy link
Contributor

@sloretz sloretz commented Dec 9, 2021

Split from #858

This fixes a circular import between time.py and clock.py. Both need the ClockType type, which comes from _rclpy_pybind11, but time.py was importing it from clock.py. That forced clock.py to import Time inside functions that used it.

I also added type annotations where I touched code.

Type hints where I touched code

Signed-off-by: Shane Loretz <[email protected]>
@sloretz sloretz self-assigned this Dec 9, 2021
@j-rivero j-rivero self-requested a review December 9, 2021 19:44
self, *,
seconds=0, nanoseconds=0,
clock_type: _rclpy.ClockType = _rclpy.ClockType.SYSTEM_TIME):
if not isinstance(clock_type, _rclpy.ClockType):
Copy link

Choose a reason for hiding this comment

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

With the type annotation in the parameter, would be this redundant now?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I debated that. The type annotation allows using a tool like mypy to statically check types. Python doesn't do runtime type checking, so the type annotation is not redundant with this explicit check, but does rclpy really need runtime type checking? I decided to not make a decision on that right now and left the code as is.

Copy link

Choose a reason for hiding this comment

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

thanks for the details, sounds totally reasonable to me.

@sloretz
Copy link
Contributor Author

sloretz commented Dec 9, 2021

CI (build: --packages-up-to rclpy test: --packages-select rclpy)

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

@sloretz sloretz merged commit 3528853 into master Dec 10, 2021
@delete-merged-branch delete-merged-branch bot deleted the time_clock_circular_import branch December 10, 2021 00:05
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