Repository: astral-sh/ruff
File: crates/ty_python_semantic/src/types/relation.rs (Rust)

Code before:
                    .constraints(db)
                    .when_some_and(|constraints| {
                        constraints.iter().when_all(db, |constraint| {
                            self.has_relation_to_impl(
                                db,
                                *constraint,
                                inferable,
                                relation,
                                relation_visitor,
                                disjointness_visitor,
                            )
                        })
                    })
            }

            (Type::TypeVar(bound_typevar), _) if bound_typevar.is_inferable(db, inferable) => {
                // The implicit lower bound of a typevar is `Never`, which means
                // that it is always assignable to any other type.

                // TODO: record the unification constraints

                ConstraintSet::from(true)
            }

            // Fast path for various types that we know `object` is never a subtype of
            // (`object` can be a subtype of some protocols, but that case is handled above).
            (
                Type::NominalInstance(source),
                Type::NominalInstance(_)
                | Type::SubclassOf(_)
                | Type::Callable(_)
                | Type::ProtocolInstance(_),
            ) if source.is_object() => ConstraintSet::from(false),

            // Fast path: `object` is not a subtype of any non-inferable type variable, since the
            // type variable could be specialized to a type smaller than `object`.
            (Type::NominalInstance(source), Type::TypeVar(typevar))
                if source.is_object() && !typevar.is_inferable(db, inferable) =>
            {
                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)

Review comment (suggestion):
```suggestion
            // (`object` can be a subtype of some protocols, or of itself, but those cases are
            // handled above).
```

Code after:
                    .constraints(db)
                    .when_some_and(|constraints| {
                        constraints.iter().when_all(db, |constraint| {
                            self.has_relation_to_impl(
                                db,
                                *constraint,
                                inferable,
                                relation,
                                relation_visitor,
                                disjointness_visitor,
                            )
                        })
                    })
            }

            (Type::TypeVar(bound_typevar), _) if bound_typevar.is_inferable(db, inferable) => {
                // The implicit lower bound of a typevar is `Never`, which means
                // that it is always assignable to any other type.

                // TODO: record the unification constraints

                ConstraintSet::from(true)
            }

            // Fast path for various types that we know `object` is never a subtype of
            // (`object` can be a subtype of some protocols, or of itself, but those cases are
            // handled above).
            (
                Type::NominalInstance(source),
                Type::NominalInstance(_)
                | Type::SubclassOf(_)
                | Type::Callable(_)
                | Type::ProtocolInstance(_),
            ) if source.is_object() => ConstraintSet::from(false),

            // Fast path: `object` is not a subtype of any non-inferable type variable, since the
            // type variable could be specialized to a type smaller than `object`.
            (Type::NominalInstance(source), Type::TypeVar(typevar))
                if source.is_object() && !typevar.is_inferable(db, inferable) =>
            {
                ConstraintSet::from(false)
            }

            // `Never` is the bottom type, the empty set.
            (_, Type::Never) => ConstraintSet::from(false),

            (Type::NewTypeInstance(self_newtype), Type::NewTypeInstance(target_newtype)) => {
                self_newtype.has_relation_to_impl(db, target_newtype)
            }
            // In the special cases of `NewType`s of `float` or `complex`, the concrete base type
            // can be a union (`int | float` or `int | float | complex`). For that reason,