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

Code before:

                            if let Some(builder) =
                                self.context.report_lint(&NON_SUBSCRIPTABLE, subscript)
                            {
                                builder.into_diagnostic(format_args!(
                                    "Cannot subscript non-generic type alias"
                                ));
                            }

                            Type::unknown()
                        }
                    }
                }
                KnownInstanceType::TypeAliasType(TypeAliasType::ManualPEP695(_)) => {
                    self.infer_type_expression(slice);
                    todo_type!("Generic manual PEP-695 type alias")
                }
                KnownInstanceType::UnionType(_) => {
                    self.infer_type_expression(slice);
                    todo_type!("Generic specialization of types.UnionType")
                }
                KnownInstanceType::Literal(_) => {
                    self.infer_type_expression(slice);
                    if let Some(builder) = self.context.report_lint(&INVALID_TYPE_FORM, subscript) {
                        builder.into_diagnostic(format_args!(
                            "`typing.Literal` instances are not allowed in type expressions",
                        ));
                    }
                    Type::unknown()
                }
            },
            Type::Dynamic(DynamicType::Todo(_)) => {
                self.infer_type_expression(slice);
                value_ty
            }
            Type::ClassLiteral(class) => {
                match class.generic_context(self.db()) {
                    Some(generic_context) => {
                        let specialized_class = self.infer_explicit_class_specialization(
                            subscript,
                            value_ty,
                            class,
                            generic_context,
                        );

                        specialized_class
                            .in_type_expression(
                                self.db(),
                                self.scope(),
                                self.typevar_binding_context,
                            )

Review comment (suggestion):
If I understand correctly, we only reach this branch for cases like these:

```py
from typing import Literal

X = Literal[1, 2]

def f(a: X[int], b: Literal["foo"][str]):
    ...
```

In which case, I think I'd prefer something a bit closer to the runtime error message, which feels clearer to me:

```pytb
>>> from typing import Literal
>>> Literal[2][int]
Traceback (most recent call last):
  File "<python-input-1>", line 1, in <module>
    Literal[2][int]
    ~~~~~~~~~~^^^^^
  File "/Users/alexw/.pyenv/versions/3.13.1/lib/python3.13/typing.py", line 432, in inner
    return func(*args, **kwds)
  File "/Users/alexw/.pyenv/versions/3.13.1/lib/python3.13/typing.py", line 1473, in __getitem__
    raise TypeError(f"{self} is not a generic class")
TypeError: typing.Literal[2] is not a generic class
```

Code after:

                            if let Some(builder) =
                                self.context.report_lint(&NON_SUBSCRIPTABLE, subscript)
                            {
                                builder.into_diagnostic(format_args!(
                                    "Cannot subscript non-generic type alias"
                                ));
                            }

                            Type::unknown()
                        }
                    }
                }
                KnownInstanceType::TypeAliasType(TypeAliasType::ManualPEP695(_)) => {
                    self.infer_type_expression(slice);
                    todo_type!("Generic manual PEP-695 type alias")
                }
                KnownInstanceType::UnionType(_) => {
                    self.infer_type_expression(slice);
                    todo_type!("Generic specialization of types.UnionType")
                }
                KnownInstanceType::Literal(ty) => {
                    self.infer_type_expression(slice);
                    if let Some(builder) = self.context.report_lint(&INVALID_TYPE_FORM, subscript) {
                        builder.into_diagnostic(format_args!(
                            "`{ty}` is not a generic class",
                            ty = ty.to_union(self.db()).display(self.db())
                        ));
                    }
                    Type::unknown()
                }
            },
            Type::Dynamic(DynamicType::Todo(_)) => {
                self.infer_type_expression(slice);
                value_ty
            }
            Type::ClassLiteral(class) => {
                match class.generic_context(self.db()) {
                    Some(generic_context) => {
                        let specialized_class = self.infer_explicit_class_specialization(
                            subscript,
                            value_ty,
                            class,
                            generic_context,
                        );

                        specialized_class
                            .in_type_expression(
                                self.db(),
                                self.scope(),
                                self.typevar_binding_context,