-
Notifications
You must be signed in to change notification settings - Fork 1.6k
Improve type annotations for ament_mypy #5575
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
Improve type annotations for ament_mypy #5575
Conversation
Codecov Report✅ All modified and coverable lines are covered by tests. 🚀 New features to boost your workflow:
|
Twist, | ||
'cmd_vel', self.cmdVelCallback, 10) | ||
else: | ||
self.cmd_vel_sub = self.create_subscription( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Renamed?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It is because the same variable is used as a redefinition. Therefore, mypy
expects a Twist
definition instead of TwistStamped
$ ament_mypy --config tools/pyproject.toml nav2_loopback_sim
nav2_loopback_sim/nav2_loopback_sim/loopback_simulator.py:131:17: error: Argument 1 to "create_subscription" of "Node" has incompatible type "type[TwistStamped]"; expected "type[Twist]" [arg-type]
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This supports both - can we make the type a union?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I have renamed the variable as a Union - self.cmd_vel_sub: Union[Subscription[Twist], Subscription[TwistStamped]]
.
|
||
|
||
def transformStampedToMatrix(transform: Transform) -> np.ndarray[np.float64, np.dtype[np.float64]]: | ||
translation = transform.transform.translation |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I believe this is correct https://docs.ros.org/en/noetic/api/geometry_msgs/html/msg/TransformStamped.html
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, you are correct.
The linter was flagging it because the functional parameter was incorrectly defined as Transform
instead of TransformStamped
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Rename the function then so it is accurate to type?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The function is already named as transformStampedToMatrix
.
I have renamed the function parameter from transform: Transform
to transform: TransformStamped
.
The GitHub UI in this comment does not seem to show this change.
This change can be seen in the Files Tab section.
y1 = 0.0 | ||
|
||
x0, y0 = self.worldToMapValidated(footprint.points[0].x, footprint.points[0].y) | ||
footprint_points = cast(list[Point32], footprint.points) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we handle this better in the actual worldToMapValidated
method?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I have dropped all the cast-related fixes in this PR, as this does not seem necessary.
The CI seems to now pass without any changes to the ament_mypy
configuration.
There is a significant disconnect when I use the devcontainer
image when running the ament_mypy
linting fixes vs testing in CI using ros-tooling/action-ros-lint
.
if not self.goal_handle or not self.goal_handle.accepted: | ||
self.error('Get path was rejected!') | ||
self.status = GoalStatus.UNKNOWN | ||
self.status = GoalStatus.STATUS_UNKNOWN |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
? I think it is unknown
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I have compared the message definition to the following documentation page, and it suggests using STATUS_UNKNOWN
.
] = ActionClient(self, NavigateThroughPoses, 'navigate_through_poses') | ||
|
||
self.controller_param_cli: Client[SetParameters.Request, SetParameters.Response] = \ | ||
self.controller_param_cli: Client[SetParameters_Request, SetParameters_Response] = \ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why change to this _
format from .
format in so many places?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I have dropped this service change as well.
This is again due to the disconnect between running ament_mypy
locally vs running it in CI.
Overall I'm surprised by the number of functional changes that have been made in this PR. Are these verifiable errors? Do those demos simply not work? |
Signed-off-by: Leander Stephen D'Souza <[email protected]>
Signed-off-by: Leander Stephen D'Souza <[email protected]>
Signed-off-by: Leander Stephen D'Souza <[email protected]>
700d694
to
972e26e
Compare
There seems to be something weird going on with I am not sure if my environment is broken, but there is a significant mismatch in what the CI reports versus the local pre-commit testing with the ament linters. In this PR, I have mainly focused on porting over significant inaccuracies from the errors I see in my local environment. |
pose = PoseStamped() | ||
pose.pose.position.x = pt.x | ||
pose.pose.position.y = pt.y | ||
pose.pose.position.x = pt.position.x |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pose has a field position
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The functional parameter was incorrectly declared and is now renamed as pt: Point
.
|
||
|
||
def transformStampedToMatrix(transform: Transform) -> np.ndarray[np.float64, np.dtype[np.float64]]: | ||
translation = transform.transform.translation |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Rename the function then so it is accurate to type?
Twist, | ||
'cmd_vel', self.cmdVelCallback, 10) | ||
else: | ||
self.cmd_vel_sub = self.create_subscription( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This supports both - can we make the type a union?
Signed-off-by: Leander Stephen D'Souza <[email protected]>
Signed-off-by: Leander Stephen D'Souza <[email protected]>
Signed-off-by: Leander Stephen D'Souza <[email protected]>
45f9292
to
0c53bb5
Compare
LGTM. I have similar changes in the Following PR. For example, this doesnt pass the mypy pre-commit: client: Client[GetState.Request, GetState.Response] = \
self.node.create_client(GetState, f'{node_name}/get_state') I have to add this comment: client: Client[GetState.Request, GetState.Response] = ( # type: ignore[name-defined]
self.node.create_client(GetState, f'{node_name}/get_state') # type: ignore[arg-type] But with the comments, it didn't pass the mypy in the CI. |
043f242
to
b4d41fd
Compare
Thank you for the initial review :)
There seems to be a disconnect in running That is why the CircleCI builds show the |
Signed-off-by: Leander Stephen D'Souza <[email protected]>
b4d41fd
to
6ba5ab7
Compare
I'm unable to pass the precommit stage if those comments aren't included. |
* Enable tools directory to be mypy compliant. Signed-off-by: Leander Stephen D'Souza <[email protected]> * Enable nav2_system_tests to be mypy compliant. Signed-off-by: Leander Stephen D'Souza <[email protected]> * Enable nav2_docking to be mypy compliant. Signed-off-by: Leander Stephen D'Souza <[email protected]> * Enable nav2_simple_commander to be mypy compliant. Signed-off-by: Leander Stephen D'Souza <[email protected]> * Enable nav2_loopback_sim to be mypy compliant. Signed-off-by: Leander Stephen D'Souza <[email protected]> * Removed unused ignores for packages for mypy compliance. Signed-off-by: Leander Stephen D'Souza <[email protected]> * Added nav2_msgs path fixes to mypy compliance. Signed-off-by: Leander Stephen D'Souza <[email protected]> --------- Signed-off-by: Leander Stephen D'Souza <[email protected]>
* Enable tools directory to be mypy compliant. Signed-off-by: Leander Stephen D'Souza <[email protected]> * Enable nav2_system_tests to be mypy compliant. Signed-off-by: Leander Stephen D'Souza <[email protected]> * Enable nav2_docking to be mypy compliant. Signed-off-by: Leander Stephen D'Souza <[email protected]> * Enable nav2_simple_commander to be mypy compliant. Signed-off-by: Leander Stephen D'Souza <[email protected]> * Enable nav2_loopback_sim to be mypy compliant. Signed-off-by: Leander Stephen D'Souza <[email protected]> * Removed unused ignores for packages for mypy compliance. Signed-off-by: Leander Stephen D'Souza <[email protected]> * Added nav2_msgs path fixes to mypy compliance. Signed-off-by: Leander Stephen D'Souza <[email protected]> --------- Signed-off-by: Leander Stephen D'Souza <[email protected]>
Basic Info
Description of contribution in a few bullet points
transform3d
andgraphviz
from mypy ignored packages from warnings generated in the logs.Description of documentation updates required from your changes
Description of how this change was tested
pre-commit run --all
Future work that may be required in bullet points
--strict
flag or theament_mypy
linting yet. As it catches genuine wrong static definitions that were inserted earlier.For Maintainers:
backport-*
.