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", age=30)
    /// alice["height"]  # KeyError: 'height'
    ///
    /// bob: Person = { "name": "Bob", "age": 30 }  # typo!
    ///
    /// carol = Person(name="Carol", age=25)  # typo!
    /// ```
    pub(crate) static INVALID_KEY = {
        summary: "detects invalid subscript accesses or TypedDict literal keys",
        status: LintStatus::stable("0.0.1-alpha.17"),
        default_level: Level::Error,
    }
}

declare_lint! {
    /// ## What it does
    /// Reports runtime checks against non-runtime-checkable protocol classes.
    /// This includes explicit calls to `isinstance()`/`issubclass()` and implicit
    /// checks performed by match class patterns.
    ///
    /// ## Why is this bad?
    /// Using a non-runtime-checkable protocol in these contexts raises `TypeError`
    /// at runtime.
    ///
    /// ## Examples
    /// ```python
    /// from typing_extensions import Protocol
    ///
    /// class HasX(Protocol):
    ///     x: int
    ///
    /// def f(arg: object, arg2: type):
    ///     isinstance(arg, HasX)  # error: [isinstance-against-protocol]
    ///     issubclass(arg2, HasX)  # error: [isinstance-against-protocol]
    ///
    /// def g(arg: object):
    ///     match arg:
    ///         case HasX():  # error: [isinstance-against-protocol]
    ///             pass
    /// ```
    pub(crate) static ISINSTANCE_AGAINST_PROTOCOL = {
        summary: "reports runtime checks against non-runtime-checkable protocol classes",
        status: LintStatus::stable("0.0.10"),
        default_level: Level::Error,

Review comment (suggestion):
```suggestion
    /// Reports runtime checks against non-runtime-checkable `Protocol` classes.
    /// This includes explicit calls to `isinstance()`/`issubclass()` and implicit
    /// checks performed by `match` class patterns.
```

Code after:
    ///
    /// Creating a `TypedDict` with an unknown key is likely a mistake; if the `TypedDict` is
    /// `closed=true` it also violates the expectations of the type.
    ///
    /// ## Examples
    /// ```python
    /// from typing import TypedDict
    ///
    /// class Person(TypedDict):
    ///     name: str
    ///     age: int
    ///
    /// alice = Person(name="Alice", age=30)
    /// alice["height"]  # KeyError: 'height'
    ///
    /// bob: Person = { "name": "Bob", "age": 30 }  # typo!
    ///
    /// carol = Person(name="Carol", age=25)  # typo!
    /// ```
    pub(crate) static INVALID_KEY = {
        summary: "detects invalid subscript accesses or TypedDict literal keys",
        status: LintStatus::stable("0.0.1-alpha.17"),
        default_level: Level::Error,
    }
}

declare_lint! {
    /// ## What it does
    /// Reports runtime checks against non-runtime-checkable `Protocol` classes.
    /// This includes explicit calls to `isinstance()`/`issubclass()` and implicit
    /// checks performed by `match` class patterns.
    ///
    /// ## Why is this bad?
    /// Using a non-runtime-checkable protocol in these contexts raises `TypeError`
    /// at runtime.
    ///
    /// ## Examples
    /// ```python
    /// from typing_extensions import Protocol
    ///
    /// class HasX(Protocol):
    ///     x: int
    ///
    /// def f(arg: object, arg2: type):
    ///     isinstance(arg, HasX)  # error: [isinstance-against-protocol]
    ///     issubclass(arg2, HasX)  # error: [isinstance-against-protocol]
    ///
    /// def g(arg: object):
    ///     match arg:
    ///         case HasX():  # error: [isinstance-against-protocol]
    ///             pass