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

Pydantic model not detected by RUF012 #13630

Open
cbornet opened this issue Oct 4, 2024 · 3 comments
Open

Pydantic model not detected by RUF012 #13630

cbornet opened this issue Oct 4, 2024 · 3 comments
Labels
multifile-analysis Requires analysis across multiple files

Comments

@cbornet
Copy link

cbornet commented Oct 4, 2024

  • List of keywords you searched for before creating this issue: pydantic ruf012
  • The current Ruff version : 0.5.0

RUF012 normally ignores pydantic models but not when the class inherits from an imported model.
Eg: file b.py

from pydantic import BaseModel

class B(BaseModel):
    pass

file a.py

from pydantic import BaseModel
from b import B

class Foo(B):
    foo: list[str] = []

class C(BaseModel):
    pass

class Bar(C):
    bar: list[str] = []

Then run ruff

ruff check --select RUF012
a.py:5:22: RUF012 Mutable class attributes should be annotated with `typing.ClassVar`
  |
4 | class Foo(B):
5 |     foo: list[str] = []
  |                      ^^ RUF012
6 |
7 | class C(BaseModel):
  |

Found 1 error.

I would expect ruff to not error.

@zanieb
Copy link
Member

zanieb commented Oct 4, 2024

Ruff doesn't support multi-file analysis yet, we can't inspect the type across the import boundary

xref #7447

@zanieb zanieb added the multifile-analysis Requires analysis across multiple files label Oct 4, 2024
@cbornet
Copy link
Author

cbornet commented Oct 4, 2024

Thanks for the info. I'll follow #7447 with interest then.

@zanieb
Copy link
Member

zanieb commented Oct 4, 2024

We're actively working on it, but it's a ways out.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
multifile-analysis Requires analysis across multiple files
Projects
None yet
Development

No branches or pull requests

2 participants