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

Code before:
impl<'db> VarianceInferable<'db> for ClassLiteral<'db> {
    fn variance_of(self, db: &'db dyn Db, typevar: BoundTypeVarInstance<'db>) -> TypeVarVariance {
        match self {
            Self::Static(class) => class.variance_of(db, typevar),
            Self::Dynamic(_) => TypeVarVariance::Bivariant,
        }
    }
}

/// A class created dynamically via a three-argument `type()` call.
///
/// For example:
/// ```python
/// Foo = type("Foo", (Base,), {"attr": 1})
/// ```
///
/// The type of `Foo` would be `<class 'Foo'>` where `Foo` is a `DynamicClassLiteral` with:
/// - name: "Foo"
/// - bases: [Base]
///
/// This is called "dynamic" because the class is created dynamically at runtime
/// via a function call rather than a class statement.
///
/// # Salsa interning
///
/// This is a salsa interned struct. Two different `type()` calls always produce
/// distinct `DynamicClassLiteral` instances, even if they have the same name and bases:
///
/// ```python
/// Foo1 = type("Foo", (Base,), {})
/// Foo2 = type("Foo", (Base,), {})
/// # Foo1 and Foo2 are distinct types
/// ```
///
/// The `anchor` field provides stable identity:
/// - For assigned `type()` calls, the `Definition` uniquely identifies the class.
/// - For dangling `type()` calls, a relative node offset anchored to the enclosing scope
///   provides stable identity that only changes when the scope itself changes.
#[salsa::interned(debug, heap_size=ruff_memory_usage::heap_size)]
#[derive(PartialOrd, Ord)]
pub struct DynamicClassLiteral<'db> {
    /// The name of the class (from the first argument to `type()`).
    #[returns(ref)]
    pub name: Name,

    /// The base classes (from the second argument to `type()`).
    #[returns(deref)]
    pub bases: Box<[ClassBase<'db>]>,

    /// The scope containing the `type()` call.
    pub scope: ScopeId<'db>,

Review comment (suggestion):
```suggestion
/// This is a Salsa-interned struct. Two different `type()` calls always produce
```

Code after:
            Self::Static(class) => class.variance_of(db, typevar),
            Self::Dynamic(_) => TypeVarVariance::Bivariant,
        }
    }
}

/// A class created dynamically via a three-argument `type()` call.
///
/// For example:
/// ```python
/// Foo = type("Foo", (Base,), {"attr": 1})
/// ```
///
/// The type of `Foo` would be `<class 'Foo'>` where `Foo` is a `DynamicClassLiteral` with:
/// - name: "Foo"
/// - bases: [Base]
///
/// This is called "dynamic" because the class is created dynamically at runtime
/// via a function call rather than a class statement.
///
/// # Salsa interning
///
/// This is a Salsa-interned struct. Two different `type()` calls always produce
/// distinct `DynamicClassLiteral` instances, even if they have the same name and bases:
///
/// ```python
/// Foo1 = type("Foo", (Base,), {})
/// Foo2 = type("Foo", (Base,), {})
/// # Foo1 and Foo2 are distinct types
/// ```
///
/// The `anchor` field provides stable identity:
/// - For assigned `type()` calls, the `Definition` uniquely identifies the class.
/// - For dangling `type()` calls, a relative node offset anchored to the enclosing scope
///   provides stable identity that only changes when the scope itself changes.
#[salsa::interned(debug, heap_size=ruff_memory_usage::heap_size)]
#[derive(PartialOrd, Ord)]
pub struct DynamicClassLiteral<'db> {
    /// The name of the class (from the first argument to `type()`).
    #[returns(ref)]
    pub name: Name,

    /// The base classes (from the second argument to `type()`).
    #[returns(deref)]
    pub bases: Box<[ClassBase<'db>]>,

    /// The anchor for this dynamic class, providing stable identity.
    ///
    /// - `Definition`: The `type()` call is assigned to a variable. The definition
    ///   uniquely identifies this class and can be used to find the `type()` call.
    /// - `ScopeOffset`: The `type()` call is "dangling" (not assigned). The offset