[red-knot] Infer attribute expressions in type annotations (#13967)

This commit is contained in:
Alex Waygood 2024-10-29 11:06:44 +00:00 committed by GitHub
parent d2c9f5e43c
commit 8d98aea6c4
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 24 additions and 11 deletions

View file

@ -3542,15 +3542,16 @@ impl<'db> TypeInferenceBuilder<'db> {
let ty = match expression {
ast::Expr::Name(name) => {
debug_assert!(
name.ctx.is_load(),
"name in a type expression is always 'load' but got: '{:?}'",
name.ctx
);
debug_assert_eq!(name.ctx, ast::ExprContext::Load);
self.infer_name_expression(name).to_instance(self.db)
}
ast::Expr::Attribute(attribute_expression) => {
debug_assert_eq!(attribute_expression.ctx, ast::ExprContext::Load);
self.infer_attribute_expression(attribute_expression)
.to_instance(self.db)
}
ast::Expr::NoneLiteral(_literal) => Type::None,
// TODO: parse the expression and check whether it is a string annotation.
@ -3684,11 +3685,6 @@ impl<'db> TypeInferenceBuilder<'db> {
self.infer_fstring_expression(fstring);
Type::Unknown
}
//
ast::Expr::Attribute(attribute) => {
self.infer_attribute_expression(attribute);
Type::Unknown
}
ast::Expr::List(list) => {
self.infer_list_expression(list);
Type::Unknown