Skip to content

Conversation

leander-dsouza
Copy link
Contributor

@leander-dsouza leander-dsouza commented Oct 2, 2025


Basic Info

Info Please fill out this column
Ticket(s) this relates #5565
Primary OS tested on Ubuntu
Robotic platform tested on N/A
Does this PR contain AI-generated software? No
Was this PR description generated by AI software? No

Description of contribution in a few bullet points

  • Fix incorrect methods and static definitions.
  • Drop transform3d and graphviz from mypy ignored packages from warnings generated in the logs.

Description of documentation updates required from your changes

  • N/A

Description of how this change was tested

  • Performed linting validation using pre-commit run --all

Future work that may be required in bullet points

  • I do not think we should remove the --strict flag or the ament_mypy linting yet. As it catches genuine wrong static definitions that were inserted earlier.

For Maintainers:

  • Check that any new parameters added are updated in docs.nav2.org
  • Check that any significant change is added to the migration guide
  • Check that any new features OR changes to existing behaviors are reflected in the tuning guide
  • Check that any new functions have Doxygen added
  • Check that any new features have test coverage
  • Check that any new plugins is added to the plugins page
  • If BT Node, Additionally: add to BT's XML index of nodes for groot, BT package's readme table, and BT library lists
  • Should this be backported to current distributions? If so, tag with backport-*.

Copy link

codecov bot commented Oct 2, 2025

Codecov Report

✅ All modified and coverable lines are covered by tests.
see 3 files with indirect coverage changes

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@leander-dsouza leander-dsouza marked this pull request as ready for review October 2, 2025 13:10
Twist,
'cmd_vel', self.cmdVelCallback, 10)
else:
self.cmd_vel_sub = self.create_subscription(
Copy link
Member

Choose a reason for hiding this comment

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

Renamed?

Copy link
Contributor Author

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]

Copy link
Member

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?

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 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
Copy link
Member

Choose a reason for hiding this comment

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

Copy link
Contributor Author

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.

Copy link
Member

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?

Copy link
Contributor Author

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)
Copy link
Member

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?

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 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
Copy link
Member

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

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 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] = \
Copy link
Member

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?

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 have dropped this service change as well.

This is again due to the disconnect between running ament_mypy locally vs running it in CI.

@SteveMacenski
Copy link
Member

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?

@leander-dsouza leander-dsouza marked this pull request as draft October 3, 2025 09:52
@leander-dsouza leander-dsouza changed the title Fix the ament_mypy workflow Improve type annotations for ament_mypy Oct 3, 2025
@leander-dsouza leander-dsouza marked this pull request as ready for review October 3, 2025 10:30
@leander-dsouza
Copy link
Contributor Author

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?

There seems to be something weird going on with ament_mypy CI, as it momentarily failed yesterday without any changes to main, and it fixed itself hours later.

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.
You can verify the mismatch by simply running pre-commit run --all in your workspace.

pose = PoseStamped()
pose.pose.position.x = pt.x
pose.pose.position.y = pt.y
pose.pose.position.x = pt.position.x
Copy link
Member

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

Copy link
Contributor Author

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
Copy link
Member

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(
Copy link
Member

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?

@leander-dsouza
Copy link
Contributor Author

I have added a new commit to the PR, fixing some incorrect paths from nav2_msgs.
This is motivated by some of the fixes done in #5565.

I would like to request @ajtudela for a short review in hopes that it may fix the ament_mypy CI issues in his PR.

@ajtudela
Copy link
Contributor

ajtudela commented Oct 6, 2025

I have added a new commit to the PR, fixing some incorrect paths from nav2_msgs. This is motivated by some of the fixes done in #5565.

I would like to request @ajtudela for a short review in hopes that it may fix the ament_mypy CI issues in his PR.

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.

@leander-dsouza leander-dsouza force-pushed the ament-mypy-fixes branch 2 times, most recently from 043f242 to b4d41fd Compare October 6, 2025 11:31
@leander-dsouza
Copy link
Contributor Author

LGTM. I have similar changes in the Following PR.

Thank you for the initial review :)

For example, this doesnt pass the mypy pre-commit:
But with the comments, it didn't pass the mypy in the CI.

There seems to be a disconnect in running ament_mypy locally, and separately in the CI, hence the CI does not need these ignored comments.

That is why the CircleCI builds show the unused-ignore error messages.

Signed-off-by: Leander Stephen D'Souza <[email protected]>
@SteveMacenski SteveMacenski merged commit 269d480 into ros-navigation:main Oct 6, 2025
16 checks passed
@ajtudela
Copy link
Contributor

ajtudela commented Oct 6, 2025

LGTM. I have similar changes in the Following PR.

Thank you for the initial review :)

For example, this doesnt pass the mypy pre-commit:
But with the comments, it didn't pass the mypy in the CI.

There seems to be a disconnect in running ament_mypy locally, and separately in the CI, hence the CI does not need these ignored comments.

That is why the CircleCI builds show the unused-ignore error messages.

I'm unable to pass the precommit stage if those comments aren't included.

silanus23 pushed a commit to silanus23/navigation2 that referenced this pull request Oct 11, 2025
* 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]>
Jad-ELHAJJ pushed a commit to Jad-ELHAJJ/navigation2 that referenced this pull request Oct 16, 2025
* 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]>
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.

3 participants