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

Code before:
                    && self.has_dataclass_param(db, field_policy, DataclassFlags::FROZEN)
                {
                    if let Some(builder) = context.report_lint(
                        &INVALID_DATACLASS_OVERRIDE,
                        literal.node(db, context.file(), context.module()),
                    ) {
                        let mut diagnostic = builder.into_diagnostic(format_args!(
                            "Cannot overwrite attribute `{}` in class `{}`",
                            name,
                            self.name(db)
                        ));
                        diagnostic.info(name);
                    }
                }
            }

            if matches!(name.as_str(), "__lt__" | "__le__" | "__gt__" | "__ge__") {
                if let CodeGeneratorKind::DataclassLike(_) = field_policy
                    && self.has_dataclass_param(db, field_policy, DataclassFlags::ORDER)
                {
                    if let Some(builder) = context.report_lint(
                        &INVALID_DATACLASS_OVERRIDE,
                        literal.node(db, context.file(), context.module()),
                    ) {
                        let mut diagnostic = builder.into_diagnostic(format_args!(
                            "Cannot overwrite attribute `{}` in class `{}`",
                            name,
                            self.name(db)
                        ));
                        diagnostic.info(name);
                    }
                }
            }
        }
    }

    /// Returns a list of all annotated attributes defined in the body of this class. This is similar
    /// to the `__annotations__` attribute at runtime, but also contains default values.
    ///
    /// For a class body like
    /// ```py
    /// @dataclass
    /// class C:
    ///     x: int
    ///     y: str = "a"
    /// ```
    /// we return a map `{"x": (int, None), "y": (str, Some(Literal["a"]))}`.
    pub(super) fn own_fields(
        self,
        db: &'db dyn Db,
        specialization: Option<Specialization<'db>>,

Review comment (suggestion):
the diagnostic emitted by mypy is:

```bash
main.py:9: error: You may not have a custom "__ge__" method when "order" is True  [misc]
```

which is different from what it emits for overridden `__setattr__` | `__delattr__`. this pr just uses the same message that we emit for `__setattr__` | `__delattr__` - open to feedback here

Code after:
                continue;
            };

            match name.as_str() {
                "__setattr__" | "__delattr__" => {
                    if let CodeGeneratorKind::DataclassLike(_) = field_policy
                        && self.has_dataclass_param(db, field_policy, DataclassFlags::FROZEN)
                    {
                        if let Some(builder) = context.report_lint(
                            &INVALID_DATACLASS_OVERRIDE,
                            literal.node(db, context.file(), context.module()),
                        ) {
                            let mut diagnostic = builder.into_diagnostic(format_args!(
                                "Cannot overwrite attribute `{}` in frozen dataclass `{}`",
                                name,
                                self.name(db)
                            ));
                            diagnostic.info(name);
                        }
                    }
                }
                "__lt__" | "__le__" | "__gt__" | "__ge__" => {
                    if let CodeGeneratorKind::DataclassLike(_) = field_policy
                        && self.has_dataclass_param(db, field_policy, DataclassFlags::ORDER)
                    {
                        if let Some(builder) = context.report_lint(
                            &INVALID_DATACLASS_OVERRIDE,
                            literal.node(db, context.file(), context.module()),
                        ) {
                            let mut diagnostic = builder.into_diagnostic(format_args!(
                                "Cannot overwrite attribute `{}` in dataclass `{}` with `order=True`",
                                name,
                                self.name(db)
                            ));
                            diagnostic.info(name);
                        }
                    }
                }
                _ => {}
            }
        }
    }

    /// Returns a list of all annotated attributes defined in the body of this class. This is similar
    /// to the `__annotations__` attribute at runtime, but also contains default values.
    ///
    /// For a class body like
    /// ```py
    /// @dataclass
    /// class C:
    ///     x: int