Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

RUF012 warns for subclasses of Pydantic classes #5639

Open
roikoren755 opened this issue Jul 10, 2023 · 5 comments
Open

RUF012 warns for subclasses of Pydantic classes #5639

roikoren755 opened this issue Jul 10, 2023 · 5 comments
Labels
bug Something isn't working multifile-analysis Requires analysis across multiple files

Comments

@roikoren755
Copy link

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
Copy link

macieyng commented Dec 2, 2023

Hi @charliermarsh 👋 Any eta on this issue?

@mikeleppane
Copy link
Contributor

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

@danieleades
Copy link

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
Copy link

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
Copy link
Contributor

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

@MichaReiser MichaReiser added the multifile-analysis Requires analysis across multiple files label Apr 21, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working multifile-analysis Requires analysis across multiple files
Projects
None yet
Development

No branches or pull requests

8 participants