From b61b0edeea68b1b957efbb8c58e89817212e527d Mon Sep 17 00:00:00 2001 From: Charlie Marsh Date: Fri, 26 Jan 2024 06:54:48 -0800 Subject: [PATCH] Add Pydantic's `BaseConfig` to default-copy list (#9650) Closes https://github.com/astral-sh/ruff/issues/9647. --- .../resources/test/fixtures/ruff/RUF012.py | 12 ++++++++++++ crates/ruff_linter/src/rules/ruff/rules/helpers.rs | 2 +- 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/crates/ruff_linter/resources/test/fixtures/ruff/RUF012.py b/crates/ruff_linter/resources/test/fixtures/ruff/RUF012.py index c1e84fb080b28..d2ae74bc4b769 100644 --- a/crates/ruff_linter/resources/test/fixtures/ruff/RUF012.py +++ b/crates/ruff_linter/resources/test/fixtures/ruff/RUF012.py @@ -67,3 +67,15 @@ class G(F): without_annotation = [] class_variable: ClassVar[list[int]] = [] final_variable: Final[list[int]] = [] + + +from pydantic import BaseConfig + + +class H(BaseModel): + class Config(BaseConfig): + mutable_default: list[int] = [] + immutable_annotation: Sequence[int] = [] + without_annotation = [] + class_variable: ClassVar[list[int]] = [] + final_variable: Final[list[int]] = [] diff --git a/crates/ruff_linter/src/rules/ruff/rules/helpers.rs b/crates/ruff_linter/src/rules/ruff/rules/helpers.rs index 1e2f2c828e2e8..c646509435945 100644 --- a/crates/ruff_linter/src/rules/ruff/rules/helpers.rs +++ b/crates/ruff_linter/src/rules/ruff/rules/helpers.rs @@ -59,7 +59,7 @@ pub(super) fn has_default_copy_semantics( analyze::class::any_call_path(class_def, semantic, &|call_path| { matches!( call_path.as_slice(), - ["pydantic", "BaseModel" | "BaseSettings"] + ["pydantic", "BaseModel" | "BaseSettings" | "BaseConfig"] | ["pydantic_settings", "BaseSettings"] | ["msgspec", "Struct"] )