mirror of https://github.com/astral-sh/ruff
Support `pydantic.BaseSettings` in `mutable-class-default` (#5312)
Closes #5308.
This commit is contained in:
parent
5dd00b19e6
commit
1c2be54b4a
|
|
@ -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"]
|
||||||
|
)
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue