From 1c2be54b4a4849cfcfdca5f529cfd2beee58d3be Mon Sep 17 00:00:00 2001 From: Charlie Marsh Date: Thu, 22 Jun 2023 15:27:05 -0400 Subject: [PATCH] Support `pydantic.BaseSettings` in `mutable-class-default` (#5312) Closes #5308. --- crates/ruff/src/rules/ruff/rules/helpers.rs | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/crates/ruff/src/rules/ruff/rules/helpers.rs b/crates/ruff/src/rules/ruff/rules/helpers.rs index 9643508cb7..944b1b52a2 100644 --- a/crates/ruff/src/rules/ruff/rules/helpers.rs +++ b/crates/ruff/src/rules/ruff/rules/helpers.rs @@ -37,11 +37,14 @@ pub(super) fn is_dataclass(class_def: &ast::StmtClassDef, semantic: &SemanticMod }) } -/// Returns `true` if the given class is a Pydantic `BaseModel`. +/// Returns `true` if the given class is a Pydantic `BaseModel` or `BaseSettings` subclass. pub(super) fn is_pydantic_model(class_def: &ast::StmtClassDef, semantic: &SemanticModel) -> bool { class_def.bases.iter().any(|expr| { semantic.resolve_call_path(expr).map_or(false, |call_path| { - matches!(call_path.as_slice(), ["pydantic", "BaseModel"]) + matches!( + call_path.as_slice(), + ["pydantic", "BaseModel" | "BaseSettings"] + ) }) }) }