mirror of
https://github.com/astral-sh/ruff.git
synced 2025-08-17 09:00:26 +00:00
Improve inference capabilities of the BuiltinTypeChecker
(#10976)
This commit is contained in:
parent
65edbfe62f
commit
4284e079b5
7 changed files with 63 additions and 11 deletions
|
@ -539,7 +539,7 @@ trait BuiltinTypeChecker {
|
|||
/// Check annotation expression to match the intended type.
|
||||
fn match_annotation(annotation: &Expr, semantic: &SemanticModel) -> bool {
|
||||
let value = map_subscript(annotation);
|
||||
Self::match_builtin_type(value, semantic)
|
||||
semantic.match_builtin_expr(value, Self::BUILTIN_TYPE_NAME)
|
||||
|| semantic.match_typing_expr(value, Self::TYPING_NAME)
|
||||
}
|
||||
|
||||
|
@ -562,15 +562,7 @@ trait BuiltinTypeChecker {
|
|||
let Expr::Call(ast::ExprCall { func, .. }) = initializer else {
|
||||
return false;
|
||||
};
|
||||
Self::match_builtin_type(func.as_ref(), semantic)
|
||||
}
|
||||
|
||||
/// Check if the given expression names the builtin type.
|
||||
fn match_builtin_type(type_expr: &Expr, semantic: &SemanticModel) -> bool {
|
||||
let Expr::Name(ast::ExprName { id, .. }) = type_expr else {
|
||||
return false;
|
||||
};
|
||||
id == Self::BUILTIN_TYPE_NAME && semantic.is_builtin(Self::BUILTIN_TYPE_NAME)
|
||||
semantic.match_builtin_expr(func, Self::BUILTIN_TYPE_NAME)
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue