Avoid inferring invalid expr types for string annotation (#14447)

## Summary

fixes: #14440

## Test Plan

Add a test case with all the invalid expressions in a string annotation
context.
This commit is contained in:
Dhruv Manilawala 2024-11-25 21:27:03 +05:30 committed by GitHub
parent fab1b0d546
commit 5a30ec0df6
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 32 additions and 1 deletions

View file

@ -4374,6 +4374,10 @@ impl<'db> TypeInferenceBuilder<'db> {
todo_type!()
}
// Avoid inferring the types of invalid type expressions that have been parsed from a
// string annotation, as they are not present in the semantic index.
_ if self.deferred_state.in_string_annotation() => Type::Unknown,
// Forms which are invalid in the context of annotation expressions: we infer their
// nested expressions as normal expressions, but the type of the top-level expression is
// always `Type::Unknown` in these cases.
@ -4457,7 +4461,6 @@ impl<'db> TypeInferenceBuilder<'db> {
self.infer_slice_expression(slice);
Type::Unknown
}
ast::Expr::IpyEscapeCommand(_) => todo!("Implement Ipy escape command support"),
}
}