ruff icon indicating copy to clipboard operation
ruff copied to clipboard

RUF012 warns for subclasses of Pydantic classes

Open roikoren755 opened this issue 1 year ago • 5 comments

First of all, once again, I'd like to thank you for a great library.

The recently added RUF012 rule warns with false positives for classes that extend a Pydantic model.

from pydantic import BaseModel


class A(BaseModel):
    lst = []


class B(A):
    lst2 = []  # RUF012

Ruff version: ruff 0.0.277

roikoren755 avatar Jul 10 '23 10:07 roikoren755

Hi @charliermarsh 👋 Any eta on this issue?

macieyng avatar Dec 02 '23 15:12 macieyng

I think this can be closed? At least the given example cannot be reproduced unless there's something more to it.

mikeleppane avatar Jan 30 '24 06:01 mikeleppane

I think this can be closed? At least the given example cannot be reproduced unless there's something more to it.

the comment on the linked pull request suggests the fix only works for direct inheritance, and not transitive inheritance

danieleades avatar Feb 27 '24 12:02 danieleades

Perhaps it would be worth having an option to specify the parent classes to ignore when applying this rule?

For example, I'm using Beanie and running into a similar issue whereby this rule should be ignored for beanie.Document subclasses.

Something like;

[tool.ruff.lint.ruff]
ignore-ruf012-classes = ["pydantic.BaseModel", "beanie.Document"]

henrybetts avatar Mar 22 '24 13:03 henrybetts

Should the tag multifile-analysis be added, as base classes could be in other files?

JonathanPlasse avatar Apr 21 '24 16:04 JonathanPlasse