diff --git a/crates/ty_python_semantic/src/types.rs b/crates/ty_python_semantic/src/types.rs index 3a2b9ed1ec..08a4af0148 100644 --- a/crates/ty_python_semantic/src/types.rs +++ b/crates/ty_python_semantic/src/types.rs @@ -1446,7 +1446,11 @@ impl<'db> Type<'db> { /// intersection simplification dependent on the order in which elements are added), so we do /// not use this more general definition of subtyping. pub(crate) fn is_subtype_of(self, db: &'db dyn Db, target: Type<'db>) -> bool { - self.when_subtype_of(db, target).is_always_satisfied() + let valid_specializations = + (self.valid_specializations(db)).and(db, || target.valid_specializations(db)); + valid_specializations + .implies(db, || self.when_subtype_of(db, target)) + .is_always_satisfied() } /// Return the constraints under which this type is a [subtype of] type `target`. (See @@ -1470,7 +1474,11 @@ impl<'db> Type<'db> { /// /// [assignable to]: https://typing.python.org/en/latest/spec/concepts.html#the-assignable-to-or-consistent-subtyping-relation pub(crate) fn is_assignable_to(self, db: &'db dyn Db, target: Type<'db>) -> bool { - self.when_assignable_to(db, target).is_always_satisfied() + let valid_specializations = + (self.valid_specializations(db)).and(db, || target.valid_specializations(db)); + valid_specializations + .implies(db, || self.when_assignable_to(db, target)) + .is_always_satisfied() } /// Returns the constraints under which this type is [assignable to] type `target`.