diff --git a/crates/red_knot_python_semantic/resources/mdtest/annotations/string_annotations.md b/crates/red_knot_python_semantic/resources/mdtest/annotations/string_annotations.md new file mode 100644 index 0000000000..0d6fe841bd --- /dev/null +++ b/crates/red_knot_python_semantic/resources/mdtest/annotations/string_annotations.md @@ -0,0 +1,9 @@ +# String annotations + +```py +def f() -> "int": + return 1 + +# TODO: We do not support string annotations, but we should not panic if we encounter them +reveal_type(f()) # revealed: @Todo +``` diff --git a/crates/red_knot_python_semantic/src/types/infer.rs b/crates/red_knot_python_semantic/src/types/infer.rs index c7838114e1..f817e39e00 100644 --- a/crates/red_knot_python_semantic/src/types/infer.rs +++ b/crates/red_knot_python_semantic/src/types/infer.rs @@ -3725,7 +3725,10 @@ impl<'db> TypeInferenceBuilder<'db> { // TODO: parse the expression and check whether it is a string annotation, since they // can be annotation expressions distinct from type expressions. // https://typing.readthedocs.io/en/latest/spec/annotations.html#string-annotations - ast::Expr::StringLiteral(_literal) => Type::Todo, + ast::Expr::StringLiteral(_literal) => { + self.store_expression_type(expression, Type::Todo); + Type::Todo + } // Annotation expressions also get special handling for `*args` and `**kwargs`. ast::Expr::Starred(starred) => self.infer_starred_expression(starred),