Fix mypy and switch to precommit hooks#5837
Fix mypy and switch to precommit hooks#5837mini-1235 wants to merge 19 commits intoros-navigation:mainfrom
Conversation
Signed-off-by: mini-1235 <mauricepurnawan@gmail.com>
Signed-off-by: mini-1235 <mauricepurnawan@gmail.com>
Signed-off-by: mini-1235 <mauricepurnawan@gmail.com>
Signed-off-by: mini-1235 <mauricepurnawan@gmail.com>
Signed-off-by: mini-1235 <mauricepurnawan@gmail.com>
Signed-off-by: mini-1235 <mauricepurnawan@gmail.com>
Signed-off-by: mini-1235 <mauricepurnawan@gmail.com>
Signed-off-by: mini-1235 <mauricepurnawan@gmail.com>
|
Sorry for spamming :(, I will fix this tomorrow |
|
@mini-1235 Thank you for taking this on, it's super annoying, I have to comment out ament_mypy to use pre-commit 😭 |
SteveMacenski
left a comment
There was a problem hiding this comment.
Alot of specific types were made into Any, I think we should be as specific as possible.
asserts should be removed from any runtime code (tests are fine). We don't want programs to terminate.
Also, check CI's output.
Signed-off-by: Maurice <mauricepurnawan@gmail.com>
Signed-off-by: mini-1235 <mauricepurnawan@gmail.com>
|
@SteveMacenski I have reverted some changes from my PR so you can take a look at the errors: https://github.com/ros-navigation/navigation2/actions/runs/20756574184/job/59600183826?pr=5837 Let me know how you would like me to proceed with these errors |
|
It looks like we'd have to cast it in some way Which ... works but also means that all ROS messages are broken (!). I'd say disable it instead The other one is like: I don't see any solution to this other than having mypy stubs added for ROS message generation (Which should have been happening before?) -- so just This feels like a major break to ament_mypy / ROS messages with mypy. @tonynajjar do you see where / when this happened? It seems like this may warrant reverting if it just breaks the use of mypy for everything. We just are going to add exceptions/skip rules galore with defeats the purpose of trying. ROS 2 message need to have useful stubs. Don't we have other python code interacting with ROS messages/services/actions -- why aren't those triggering issues like this parsing its internal parts / indexing vectors? Do they already have |
|
After taking a closer look at both ament_mypy and mypy, I would like to correct my earlier assumption:
It seems like we end up needing to fix mypy after almost every rolling sync, and sometimes the newly introduced errors don't really make sense to me. At this point, it seems more likely that the issue is caused by other packages in the base image instead of ament_mypy. The packages in the base image haven't been updated since July 23, 2025, which I believe is why we're no longer encountering the mypy issue. I actually prepared this PR on Sunday night. When I tried to submit it on Monday, I started hitting different errors that I had to fix again(also today, when I tried to show you the errors), I honestly don't understand why 😮💨 |
Sorry, no i don't know when it broke |
|
Quoting from https://docs.astral.sh/ruff/faq/#how-does-ruff-compare-to-mypy-or-pyright-or-pyre:
Based on this, I don't think Ruff can replace mypy. I also tested the other two type checkers mentioned in the docs: pyright: https://gist.github.com/mini-1235/3b61429672788eecb0642607207af3bf Neither of them looks better than mypy in our case It seems likely that: Since the next rolling sync should be happening soon (starting tomorrow?), I guess we can wait a few more days to see whether the results change, and then decide whether it makes sense to keep or drop mypy checking in the codebase |
|
I guess we can wait yes. I would love to have type checking properly in our CI, but if we're just going to mark everything as Without some clarity / help as to what they think we should do, I think the only reasonable time efficient action for us is to remove mypy checks. We aren't a primarily python repository and there's only one demo-ware package that has run-time user exposed python, so its an unfortunate trade off of time-to-value. |
Good idea, but I am not sure where this should be filed. The warnings come from mypy, but the root cause seems to originate from other packages, so I am not sure if it's appropriate to file this in the ament_lint repo. Any idea? |
|
I'd file in rclpy and tag me with it. I think while its a linting issue, it affects linting in the rclpy as well. ... actually, how does rclpy's mypy config / codebase with linting look like? They use it, right? That should point us to a solution or do they really just have |
No, I don't think so. I tried to run ament_mypy and I can see there are a lot of errors: and ros2/rclpy#1257 is still open, so I believe that it's not fully supported yet |
|
Then maybe ament_lint then. I'm just expecting less likelihood of a response from maintainers there. Maybe this is a sign we should also drop this if rclpy isn't even using type checking. If that's not, how could anything else be expected to. |
Signed-off-by: mini-1235 <mauricepurnawan@gmail.com>
|
Linking to: ros2/rosidl_python#228 |
Signed-off-by: Maurice <mauricepurnawan@gmail.com>
|
From CI: the "indexable" error is solved after the latest sync |
|
Just append now it appears 👍 Once resolved we can remove the asserts and be done with this :-) |
|
This pull request is in conflict. Could you fix it @mini-1235? |
just to understand when to expect this, is this on us or waiting for something upstream? |
|
The PMCs are currently working on this, see more in https://openrobotics.zulipchat.com/#narrow/channel/526027-ROS-General/topic/ROS.20Python.20Message.20Array.20Field.20Mutability This will likely be resolved in the next rolling sync |
Signed-off-by: mini-1235 <mauricepurnawan@gmail.com>
320952c to
189248b
Compare
Signed-off-by: mini-1235 <mauricepurnawan@gmail.com>
Signed-off-by: mini-1235 <mauricepurnawan@gmail.com>
Signed-off-by: mini-1235 <mauricepurnawan@gmail.com>
|
@SteveMacenski Can we comment out ament_mypy from the pre-commit config on main until it is fixed? It's making my life difficult, every time I want branch from |
|
@tonynajjar: Sure. Just comment on the ticket in parallel that it was disabled to be re-enabled later |
Based on my analysis in #5830 (comment), the base image currently used for linting was last updated ~6 months ago. This leads to inconsistent results between CI linting and running pre-commit locally. #5322, #5280, #5382, #5575 tried to fix mypy-related issues, but some of those fixes may be partially incorrect due to the outdated mypy version in CI.
This PR switches linting to use our own images to ensure they stay up to date and resolves #5830.