Improve handling of metaclasses in various linter rules (#12579)

This commit is contained in:
Alex Waygood 2024-07-30 14:48:36 +01:00 committed by GitHub
parent ac1666d6e2
commit 7a4419a2a5
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
6 changed files with 46 additions and 29 deletions

View file

@ -110,3 +110,13 @@ pub fn is_enumeration(class_def: &ast::StmtClassDef, semantic: &SemanticModel) -
)
})
}
/// Returns `true` if the given class is a metaclass.
pub fn is_metaclass(class_def: &ast::StmtClassDef, semantic: &SemanticModel) -> bool {
any_qualified_name(class_def, semantic, &|qualified_name| {
matches!(
qualified_name.segments(),
["" | "builtins", "type"] | ["abc", "ABCMeta"] | ["enum", "EnumMeta" | "EnumType"]
)
})
}