-
-
Notifications
You must be signed in to change notification settings - Fork 205
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
tests: Enable mypy type checking in pre-commit and fix typing issues #1581
base: main
Are you sure you want to change the base?
Conversation
/cc @whot don't know who else could review this |
c28d53f
to
e6b876c
Compare
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.
Isn't this throwing out the baby with the bathwater? pre-commit is relatively standard and if mypy is the issue here would it make more sense to just treat mypy special (e.g. even invoking it as part of meson test) and leave everything else that works to pre-commit?
Or like this example to wrap the mypy run into a pre-commit local script so we control mypy only. But I guess you found that one so - maybe running mypy as part of meson test is the easiest?
Oh, and adding this line to the top of really stubborn files that we cannot fix seems to help (see docs:
# mypy: disable-error-code="annotation-unchecked"
What were the specific unfixable issues you ran into here?
e6b876c
to
f114b39
Compare
Alright, a fresh mind seems to have helped. Managed to make mypy work with pre-commit by using a bunch of |
f114b39
to
404ff7e
Compare
The code also had a bug where its using instanceof on a class instead of an instance, but then also accidentally check for the negated of what it was supposed to check. Found by mypy because it complained that the variable might not have been of the right type.
This also makes mypy happy.
The type is Response|None and accessing (None).response would be wrong, so mypy correctly complains.
Response is of type Callable | Response at first but we use the Callable to always get a Response. For mypy to understand what's going on, we assign the response to a new variable res.
instead of the entire string which can contain other data, such as the bus name. Also adds an assert to ensure template is actually of type string which makes mypy happy.
Instead of trying to go on with None.
404ff7e
to
3668f12
Compare
This gets is mypy in addition to ruff check and ruff format. I spent way too many hours trying to make things work with pre-commit and I don't think it's even possible. CI runs the check script directly, the git-hooks integration only when a commit changes something in tests.