[ty] Ensure that T is disjoint from ~T even when T is a TypeVar (#17922)

Same as https://github.com/astral-sh/ruff/pull/17910 but for
disjointness
This commit is contained in:
Alex Waygood 2025-05-07 18:59:16 +01:00 committed by GitHub
parent 74fe7982ba
commit 895b6161a6
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 11 additions and 5 deletions

View file

@ -1643,6 +1643,13 @@ impl<'db> Type<'db> {
false
}
(tvar @ Type::TypeVar(_), Type::Intersection(intersection))
| (Type::Intersection(intersection), tvar @ Type::TypeVar(_))
if intersection.negative(db).contains(&tvar) =>
{
true
}
// An unbounded typevar is never disjoint from any other type, since it might be
// specialized to any type. A bounded typevar is not disjoint from its bound, and is
// only disjoint from other types if its bound is. A constrained typevar is disjoint