-
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] Improve Type::is_disjoint_from()
for KnownInstanceType
s
#15261
Conversation
|
Argh, no. This does create new property test failures. I must have had a fluky success locally. |
Okay, I fixed the new bug surfaced by the property tests. This time it was that we weren't recognising |
c44a2e7
to
8cad5be
Compare
8cad5be
to
deac0e4
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.
Nice!
| (Type::Tuple(_), Type::KnownInstance(known_instance)) => KnownClass::Tuple | ||
.to_class_literal(db) | ||
.into_class_literal() | ||
.is_some_and(|ClassLiteralType { class: tuple_class }| { | ||
!known_instance.class().is_subclass_of(db, tuple_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.
Would it be less repetitive to delegate this to "the known instance type is disjoint from KnownClass::Tuple.to_instance()
, which would end up in the prior case?
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.
Ahh, great catch! I've pushed that change. (I checked that it doesn't cause any new property test failures, as well.)
* main: (60 commits) [`ruff`] Dataclass enums (`RUF049`) (#15299) Better error message when `--config` is given a table key and a non-inline-table value (#15266) Update pre-commit dependencies (#15289) Don't fix in ecosystem check (#15267) Update Rust crate itertools to 0.14.0 (#15287) Remove accidental empty block at the bottom of `split-static-string (SIM905)` doc (#15290) Update Rust crate clearscreen to v4 (#15288) Update Rust crate insta to v1.42.0 (#15286) Update NPM Development dependencies (#15285) Update dependency uuid to v11.0.4 (#15284) Update dependency ruff to v0.8.6 (#15283) Update Rust crate syn to v2.0.95 (#15282) Update Rust crate matchit to v0.8.6 (#15281) Update Rust crate bstr to v1.11.3 (#15280) [red-knot] Future-proof `Type::is_disjoint_from()` (#15262) [red-knot] Improve `Type::is_disjoint_from()` for `KnownInstanceType`s (#15261) [red-knot] Minor simplifications and improvements to constraint narrowing logic (#15270) Allow assigning ellipsis literal as parameter default value (#14982) [red-knot] fix control flow for assignment expressions in elif tests (#15274) [`refurb`] Mark fix as unsafe when the right-hand side is a string (`FURB171`) (#15273) ...
* main: (29 commits) [`ruff`] Dataclass enums (`RUF049`) (#15299) Better error message when `--config` is given a table key and a non-inline-table value (#15266) Update pre-commit dependencies (#15289) Don't fix in ecosystem check (#15267) Update Rust crate itertools to 0.14.0 (#15287) Remove accidental empty block at the bottom of `split-static-string (SIM905)` doc (#15290) Update Rust crate clearscreen to v4 (#15288) Update Rust crate insta to v1.42.0 (#15286) Update NPM Development dependencies (#15285) Update dependency uuid to v11.0.4 (#15284) Update dependency ruff to v0.8.6 (#15283) Update Rust crate syn to v2.0.95 (#15282) Update Rust crate matchit to v0.8.6 (#15281) Update Rust crate bstr to v1.11.3 (#15280) [red-knot] Future-proof `Type::is_disjoint_from()` (#15262) [red-knot] Improve `Type::is_disjoint_from()` for `KnownInstanceType`s (#15261) [red-knot] Minor simplifications and improvements to constraint narrowing logic (#15270) Allow assigning ellipsis literal as parameter default value (#14982) [red-knot] fix control flow for assignment expressions in elif tests (#15274) [`refurb`] Mark fix as unsafe when the right-hand side is a string (`FURB171`) (#15273) ...
Summary
Two things are fixed here:
KnownInstance::TypingLiteral
) that was an instance oftyping._SpecialForm
, we currently don't recognise that this type is disjoint from a classFoo
that is a subclass oftyping._SpecialForm
. This is a bit theoretical, asKnownInstance
s in our model are generally instances of classes that cannot be subclassed (at least, not easily). However, fixing this bug revealed (thanks to the property tests) that...Type::Tuple([])
to be disjoint fromType::KnownInstance(KnownInstanceType::TypingLiteral)
.Test Plan
Type::Tuple([])
is now considered disjoint fromType::KnownInstance(KnownInstanceType::TypingLiteral)
.QUICKCHECK_TESTS=200000 cargo test -p red_knot_python_semantic -- --ignored types::property_tests::stable
to ensure that there are no new failures in the property tests