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

Code before:
    /// ```python
    /// from typing import TypedDict
    ///
    /// class Person(TypedDict):
    ///     name: str
    ///     age: int
    ///
    /// alice: Person = {"name": "Alice"}  # missing required key 'age'
    ///
    /// alice["age"]  # KeyError
    /// ```
    pub(crate) static MISSING_TYPED_DICT_KEY = {
        summary: "detects missing required keys in `TypedDict` constructors",
        status: LintStatus::stable("0.0.1-alpha.20"),
        default_level: Level::Error,
    }
}

declare_lint! {
    /// ## What it does
    /// Detects statements other than annotated declarations in `TypedDict` class bodies.
    ///
    /// ## Why is this bad?
    /// `TypedDict` class bodies aren't allowed to contain any other types of statements, and for
    /// example method definitions and field values aren't allowed. None of these will be present
    /// on instances at runtime (which are of type `dict`).
    ///
    /// ## Example
    /// ```python
    /// from typing import TypedDict
    ///
    /// class Foo(TypedDict):
    ///     def bar(self):  # error: [invalid-typed-dict-statement]
    ///         pass
    /// ```
    pub(crate) static INVALID_TYPED_DICT_STATEMENT = {
        summary: "detects invalid statements in `TypedDict` class bodies",
        status: LintStatus::stable("0.0.9"),
        default_level: Level::Error,
    }
}

declare_lint! {
    /// ## What it does
    /// Detects method overrides that violate the [Liskov Substitution Principle] ("LSP").
    ///
    /// The LSP states that an instance of a subtype should be substitutable for an instance of its supertype.
    /// Applied to Python, this means:
    /// 1. All argument combinations a superclass method accepts
    ///    must also be accepted by an overriding subclass method.
    /// 2. The return type of an overriding subclass method must be a subtype

Review comment (suggestion):
```suggestion
    /// `TypedDict` class bodies aren't allowed to contain any other types of statements. For
    /// example, method definitions and field values aren't allowed. None of these will be available
    /// on "instances of the TypedDict" at runtime (as `dict` is the runtime class of all
    /// "TypedDict instances").
```

Code after:
    /// ```python
    /// from typing import TypedDict
    ///
    /// class Person(TypedDict):
    ///     name: str
    ///     age: int
    ///
    /// alice: Person = {"name": "Alice"}  # missing required key 'age'
    ///
    /// alice["age"]  # KeyError
    /// ```
    pub(crate) static MISSING_TYPED_DICT_KEY = {
        summary: "detects missing required keys in `TypedDict` constructors",
        status: LintStatus::stable("0.0.1-alpha.20"),
        default_level: Level::Error,
    }
}

declare_lint! {
    /// ## What it does
    /// Detects statements other than annotated declarations in `TypedDict` class bodies.
    ///
    /// ## Why is this bad?
    /// `TypedDict` class bodies aren't allowed to contain any other types of statements. For
    /// example, method definitions and field values aren't allowed. None of these will be
    /// available on "instances of the `TypedDict`" at runtime (as `dict` is the runtime class of
    /// all "`TypedDict` instances").
    ///
    /// ## Example
    /// ```python
    /// from typing import TypedDict
    ///
    /// class Foo(TypedDict):
    ///     def bar(self):  # error: [invalid-typed-dict-statement]
    ///         pass
    /// ```
    pub(crate) static INVALID_TYPED_DICT_STATEMENT = {
        summary: "detects invalid statements in `TypedDict` class bodies",
        status: LintStatus::stable("0.0.9"),
        default_level: Level::Error,
    }
}

declare_lint! {
    /// ## What it does
    /// Detects method overrides that violate the [Liskov Substitution Principle] ("LSP").
    ///
    /// The LSP states that an instance of a subtype should be substitutable for an instance of its supertype.
    /// Applied to Python, this means:
    /// 1. All argument combinations a superclass method accepts
    ///    must also be accepted by an overriding subclass method.