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

[ruff] Skip SQLModel base classes for mutable-class-default (RUF012) #14949

Merged
merged 3 commits into from
Dec 13, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 24 additions & 0 deletions crates/ruff_linter/resources/test/fixtures/ruff/RUF012.py
dylwil3 marked this conversation as resolved.
Show resolved Hide resolved
Original file line number Diff line number Diff line change
Expand Up @@ -79,3 +79,27 @@ class Config(BaseConfig):
without_annotation = []
class_variable: ClassVar[list[int]] = []
final_variable: Final[list[int]] = []


def sqlmodel_import_checker():
from sqlmodel.main import SQLModel

class I(SQLModel):
id: int
mutable_default: list[int] = []

from sqlmodel import SQLModel

class J(SQLModel):
id: int
name: str


class K(SQLModel):
id: int
i_s: list[J] = []


class L(SQLModel):
id: int
i_j: list[K] = list()
1 change: 1 addition & 0 deletions crates/ruff_linter/src/rules/ruff/rules/helpers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -187,6 +187,7 @@ pub(super) fn has_default_copy_semantics(
["pydantic", "BaseModel" | "BaseSettings" | "BaseConfig"]
| ["pydantic_settings", "BaseSettings"]
| ["msgspec", "Struct"]
| ["sqlmodel", "SQLModel"]
)
})
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
---
source: crates/ruff_linter/src/rules/ruff/mod.rs
assertion_line: 82
snapshot_kind: text
---
RUF012.py:9:34: RUF012 Mutable class attributes should be annotated with `typing.ClassVar`
Expand Down Expand Up @@ -31,3 +32,13 @@ RUF012.py:25:26: RUF012 Mutable class attributes should be annotated with `typin
26 | perfectly_fine: list[int] = field(default_factory=list)
27 | class_variable: ClassVar[list[int]] = []
|

RUF012.py:89:38: RUF012 Mutable class attributes should be annotated with `typing.ClassVar`
|
87 | class I(SQLModel):
88 | id: int
89 | mutable_default: list[int] = []
| ^^ RUF012
90 |
91 | from sqlmodel import SQLModel
|
Loading