Skip to content

RUF045 on dataclass method assignment #16360

@beskep

Description

@beskep

Description

ruff version: 0.9.7
command: ruff check test.py --select RUF --preview

import functools
from collections.abc import Callable
from dataclasses import dataclass


@dataclass
class Vector:
    x: float
    y: float

    def __call__(self) -> None:
        print(self)

    # RUF045: Assignment without annotation found in dataclass body
    call = __call__

    call2: Callable[..., None] = __call__  # this makes new field

    def add(self, x: float, y: float):
        return Vector(x=self.x + x, y=self.y + y)

    # RUF045: Assignment without annotation found in dataclass body
    add_x = functools.partialmethod(add, y=0)

I am not sure if it's intended, but ruff check RUF045 for assigning a method of dataclass.

Is there a more appropriate way for typing new method, perhaps?

Metadata

Metadata

Assignees

No one assigned

    Labels

    previewRelated to preview mode featuresquestionAsking for support or clarificationruleImplementing or modifying a lint rule

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions