astral-sh / ruff

An extremely fast Python linter and code formatter, written in Rust.
https://docs.astral.sh/ruff
MIT License
32.76k stars 1.09k forks source link

RUF012 warns for subclasses of Pydantic classes #5639

Open roikoren755 opened 1 year ago

roikoren755 commented 1 year ago

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

macieyng commented 11 months ago

Hi @charliermarsh 👋 Any eta on this issue?

mikeleppane commented 9 months ago

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

danieleades commented 8 months ago

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

henrybetts commented 7 months ago

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"]
JonathanPlasse commented 6 months ago

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