-
Notifications
You must be signed in to change notification settings - Fork 1
[2/5] Type-check assertions #14
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
Conversation
31c31f3
to
58d2a77
Compare
775285c
to
d164ae4
Compare
912ea11
to
97376d2
Compare
58d2a77
to
6a5080c
Compare
25aebe9
to
12ceb41
Compare
6a5080c
to
daee4f6
Compare
12ceb41
to
1dd575e
Compare
@@ -39,8 +39,8 @@ packages = ["src/nexusrpc"] | |||
|
|||
[tool.poe.tasks] | |||
lint = [ | |||
{cmd = "uv run basedpyright src"}, | |||
{cmd = "uv run pyright src"}, |
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 test suite passes type-checking after this PR.
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.
Not applying much scrutiny to tests here, but did mention in a previous PR that reportDeprecated
is noisy on our PRs here
daee4f6
to
635a365
Compare
1dd575e
to
1d43557
Compare
635a365
to
6e68f3f
Compare
1d43557
to
76241b2
Compare
Thanks!
You might want to look at |
76241b2
to
6e7bdd3
Compare
Will look... |
tests/test_type_errors.py
Outdated
# This test is disabled since we currently have no way to be able to | ||
# assert-type-error-mypy on a line with a `type: ignore`. |
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't say I understand this, but if this is dead code, can we remove it or open an issue to follow up on it?
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.
Deleted. The issue is that:
- We would like to be able to make an assertion that a line produces a certain type error
- We would also like the test code to pass type checking
- For pyright, the current solution is to place the
type: ignore
on the line in question but instruct pyright to ignore it when performing the type error assertion check. - For mypy we have no such solution
There are probably other solutions, e.g. entirely excluding such files from our type checking in CI. I'll look into that: I think that may work because the type assertion checker does check that no there are no type errors other than the expected ones. But let's merge this as-is if that's OK, i.e. with just pyright support.
metafunc.parametrize("test_file", files_with_assertions, ids=lambda f: f.name) | ||
|
||
|
||
@pytest.mark.skipif(platform.system() == "Windows", reason="TODO: broken on Windows") |
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 open an issue to address this TODO so we don't lose track?
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 good call, done #19. There should be no technical obstacle there; I just failed to solve it within the time I had allotted to the task.
import pytest | ||
|
||
|
||
def pytest_generate_tests(metafunc: pytest.Metafunc) -> None: |
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 bit confused here. How is this used? It seems to look for certain function names but ignores them if they are in this file but I can find them nowhere else? Is this code not leveraged in this PR?
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's a pytest hook https://docs.pytest.org/en/stable/how-to/parametrize.html#pytest-generate-tests. Here we're using it to dynamically generate a test for every test file that contains type error assertion comments.
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 generates a test like this (we only have those comments in one file at the moment):
tests/test_type_errors.py::test_type_errors_pyright[test_type_checking_sync_operation.py] PASSED
AI: This commit should have tag name type-assertions and should be force-pushed to a branch of that name as necessary.
6e7bdd3
to
f6d4657
Compare
This is PR 2/5 in a stack.
Update the library for making type-check failure assertions so that it supports making assertions for multiple type checkers.
The main point of this PR is the changes to the library for type-check assertions
test_type_errors.py