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

mutable-class-default (RUF012) misinterprete the code block #9647

Closed
ArazHeydarov opened this issue Jan 26, 2024 · 6 comments · Fixed by #9650
Closed

mutable-class-default (RUF012) misinterprete the code block #9647

ArazHeydarov opened this issue Jan 26, 2024 · 6 comments · Fixed by #9650
Assignees
Labels
bug Something isn't working

Comments

@ArazHeydarov
Copy link

Hello,

RUF012 working principle seems to be broken. I'm defining a Pydantic json_encoder config however Ruff detects it as typing annotation and raises an error when I check.

Code:

from bson import ObjectId
from pydantic import BaseConfig, BaseModel


class MongoModel(BaseModel):
    class Config(BaseConfig):
        allow_population_by_field_name = True
        json_encoders = {ObjectId: str}

Command: ruff check .

Result:

src/models/mongo_model.py:8:25: RUF012 Mutable class attributes should be annotated with `typing.ClassVar`
Found 1 error.

Current settings:

[tool.ruff.lint]
extend-select = ["I", "C90", 'N', 'UP', 'ASYNC', 'RUF']

Current Ruff version:
ruff 0.1.14

@charliermarsh
Copy link
Member

It looks like BaseConfig is missing from our allowlist.

@charliermarsh charliermarsh added the bug Something isn't working label Jan 26, 2024
@charliermarsh
Copy link
Member

What is BaseConfig? I can't find it in the Pydantic docs.

@trag1c
Copy link
Contributor

trag1c commented Jan 26, 2024

What is BaseConfig? I can't find it in the Pydantic docs.

It's part of Pydantic v1: https://docs.pydantic.dev/2.0/api/config/#pydantic.config.BaseConfig

@ArazHeydarov
Copy link
Author

It's a class that is deprecated as of Pydantic 2.0. The result is the same without inheriting from that class.
I know that the Config class definition itself is deprecated.

@charliermarsh
Copy link
Member

Thank you! Will add.

@ArazHeydarov
Copy link
Author

Thank you for your quick response.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants