Support `pydantic.BaseSettings` in `mutable-class-default` (#5312)

Closes #5308.
This commit is contained in:
Charlie Marsh 2023-06-22 15:27:05 -04:00 committed by GitHub
parent 5dd00b19e6
commit 1c2be54b4a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 5 additions and 2 deletions

View File

@ -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 { pub(super) fn is_pydantic_model(class_def: &ast::StmtClassDef, semantic: &SemanticModel) -> bool {
class_def.bases.iter().any(|expr| { class_def.bases.iter().any(|expr| {
semantic.resolve_call_path(expr).map_or(false, |call_path| { 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"]
)
}) })
}) })
} }