mirror of
https://github.com/astral-sh/ruff.git
synced 2025-09-30 05:45:24 +00:00
[red-knot] Minor cleanup to Type::is_disjoint_from()
and Type::is_subtype_of()
(#15260)
This commit is contained in:
parent
6b907c1305
commit
8f0e01787f
1 changed files with 5 additions and 5 deletions
|
@ -816,8 +816,8 @@ impl<'db> Type<'db> {
|
||||||
|
|
||||||
// Note that the definition of `Type::AlwaysFalsy` depends on the return value of `__bool__`.
|
// Note that the definition of `Type::AlwaysFalsy` depends on the return value of `__bool__`.
|
||||||
// If `__bool__` always returns True or False, it can be treated as a subtype of `AlwaysTruthy` or `AlwaysFalsy`, respectively.
|
// If `__bool__` always returns True or False, it can be treated as a subtype of `AlwaysTruthy` or `AlwaysFalsy`, respectively.
|
||||||
(left, Type::AlwaysFalsy) => matches!(left.bool(db), Truthiness::AlwaysFalse),
|
(left, Type::AlwaysFalsy) => left.bool(db).is_always_false(),
|
||||||
(left, Type::AlwaysTruthy) => matches!(left.bool(db), Truthiness::AlwaysTrue),
|
(left, Type::AlwaysTruthy) => left.bool(db).is_always_true(),
|
||||||
// Currently, the only supertype of `AlwaysFalsy` and `AlwaysTruthy` is the universal set (object instance).
|
// Currently, the only supertype of `AlwaysFalsy` and `AlwaysTruthy` is the universal set (object instance).
|
||||||
(Type::AlwaysFalsy | Type::AlwaysTruthy, _) => {
|
(Type::AlwaysFalsy | Type::AlwaysTruthy, _) => {
|
||||||
target.is_equivalent_to(db, KnownClass::Object.to_instance(db))
|
target.is_equivalent_to(db, KnownClass::Object.to_instance(db))
|
||||||
|
@ -1157,7 +1157,7 @@ impl<'db> Type<'db> {
|
||||||
// multiply-inherit `type` or a subclass of it, and thus not be disjoint with
|
// multiply-inherit `type` or a subclass of it, and thus not be disjoint with
|
||||||
// `type[...]`.) Until we support finality, hardcode None, which is known to be
|
// `type[...]`.) Until we support finality, hardcode None, which is known to be
|
||||||
// final.
|
// final.
|
||||||
matches!(instance.class.known(db), Some(KnownClass::NoneType))
|
instance.class.is_known(db, KnownClass::NoneType)
|
||||||
}
|
}
|
||||||
|
|
||||||
(
|
(
|
||||||
|
@ -1186,11 +1186,11 @@ impl<'db> Type<'db> {
|
||||||
(Type::AlwaysTruthy, ty) | (ty, Type::AlwaysTruthy) => {
|
(Type::AlwaysTruthy, ty) | (ty, Type::AlwaysTruthy) => {
|
||||||
// `Truthiness::Ambiguous` may include `AlwaysTrue` as a subset, so it's not guaranteed to be disjoint.
|
// `Truthiness::Ambiguous` may include `AlwaysTrue` as a subset, so it's not guaranteed to be disjoint.
|
||||||
// Thus, they are only disjoint if `ty.bool() == AlwaysFalse`.
|
// Thus, they are only disjoint if `ty.bool() == AlwaysFalse`.
|
||||||
matches!(ty.bool(db), Truthiness::AlwaysFalse)
|
ty.bool(db).is_always_false()
|
||||||
}
|
}
|
||||||
(Type::AlwaysFalsy, ty) | (ty, Type::AlwaysFalsy) => {
|
(Type::AlwaysFalsy, ty) | (ty, Type::AlwaysFalsy) => {
|
||||||
// Similarly, they are only disjoint if `ty.bool() == AlwaysTrue`.
|
// Similarly, they are only disjoint if `ty.bool() == AlwaysTrue`.
|
||||||
matches!(ty.bool(db), Truthiness::AlwaysTrue)
|
ty.bool(db).is_always_true()
|
||||||
}
|
}
|
||||||
|
|
||||||
(Type::SubclassOf(_), _) | (_, Type::SubclassOf(_)) => {
|
(Type::SubclassOf(_), _) | (_, Type::SubclassOf(_)) => {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue