-
Notifications
You must be signed in to change notification settings - Fork 1.2k
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
[red-knot] Support TypeGuard
and TypeIs
#16314
base: main
Are you sure you want to change the base?
Conversation
} | ||
|
||
#[salsa::interned] | ||
pub struct TypeGuardType<'db> { |
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 seems that the two types are exactly identical except for the name. Could we use a shared type (similar to Class
) or make this type only thin wrapper types around a shared type? It would avoid the need for a macro
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 started with that, but the various match
/case
function ended up quite unreadable, not to mention the subtle differences (e.g., TypeGuard[]
is covariant, but TypeIs[]
is invariant). All in all, I think the current approach is the best, despite being a little bit non-DRY.
This PR is incomplete (hence the empty description). Some major issues (all reflected in tests):
|
# error: [invalid-type-guard-definition] | ||
def _(**kwargs) -> TypeIs[str]: ... | ||
|
||
class _: |
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'm not sure if it's possible or reasonable here but I found many very specific mdtests much more helpful when debugging regression than a few tests that have many unrelated assertions.
There are also fewer trade-offs when using smaller tests compared to Ruff because it doesn't require you to create a new file. A single header is enough to create an isolated test.
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.
Aren't all of these about function arity? I think this test is pretty small already, unless you mean the second file below (which is for subtype relation in TypeIs
functions)?
1f02c40
to
a6e76bc
Compare
a6e76bc
to
ade4c79
Compare
Summary
Part of #13694.
This PR's description is currently empty. See this comment for a list of unresolved major issues.
Test Plan
Markdown tests.