Add fast path for object vs unbounded inferable TypeVar
This handles the common case where we're checking if `object` (the implicit positive element of a pure negation like `~str`) is assignable to a generic type parameter like `_T` in `Iterator[_T]`. Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
@@ -672,6 +672,21 @@ impl<'db> Type<'db> {
|
||||
ConstraintSet::from(false)
|
||||
}
|
||||
|
||||
// Fast path: `object` is assignable to any inferable type variable with no upper bound
|
||||
// (or with `object` as its upper bound), which is the common case for generic
|
||||
// type parameters like `_T` in `Iterator[_T]`.
|
||||
(Type::NominalInstance(source), Type::TypeVar(typevar))
|
||||
if source.is_object()
|
||||
&& typevar.is_inferable(db, inferable)
|
||||
&& relation.is_assignability()
|
||||
&& typevar
|
||||
.typevar(db)
|
||||
.upper_bound(db)
|
||||
.is_none_or(|bound| bound.is_object()) =>
|
||||
{
|
||||
ConstraintSet::from(true)
|
||||
}
|
||||
|
||||
// Fast path: `object` is not a subtype of any callable type, since not all objects
|
||||
// are callable.
|
||||
(Type::NominalInstance(source), Type::Callable(_)) if source.is_object() => {
|
||||
|
||||
Reference in New Issue
Block a user