diff --git a/crates/red_knot_python_semantic/src/types/infer.rs b/crates/red_knot_python_semantic/src/types/infer.rs index 32104b0f07..7224ac0c9d 100644 --- a/crates/red_knot_python_semantic/src/types/infer.rs +++ b/crates/red_knot_python_semantic/src/types/infer.rs @@ -4229,6 +4229,7 @@ impl<'db> TypeInferenceBuilder<'db> { "annotation-f-string", format_args!("Type expressions cannot use f-strings"), ); + self.infer_fstring_expression(fstring); Type::Unknown } diff --git a/crates/red_knot_workspace/resources/test/corpus/95_annotation_fstring_invalid.py b/crates/red_knot_workspace/resources/test/corpus/95_annotation_fstring_invalid.py new file mode 100644 index 0000000000..119b52201c --- /dev/null +++ b/crates/red_knot_workspace/resources/test/corpus/95_annotation_fstring_invalid.py @@ -0,0 +1 @@ +x: f"Literal[{1 + 2}]" = 3 diff --git a/crates/red_knot_workspace/tests/check.rs b/crates/red_knot_workspace/tests/check.rs index eeec8cee35..f3be665151 100644 --- a/crates/red_knot_workspace/tests/check.rs +++ b/crates/red_knot_workspace/tests/check.rs @@ -272,7 +272,7 @@ const KNOWN_FAILURES: &[(&str, bool, bool)] = &[ ("crates/ruff_linter/resources/test/fixtures/pyupgrade/UP039.py", true, false), // related to circular references in type aliases (salsa cycle panic): ("crates/ruff_python_parser/resources/inline/err/type_alias_invalid_value_expr.py", true, true), - // related to f-strings in annotations (invalid syntax) + // related to circular references in f-string annotations (invalid syntax) ("crates/ruff_linter/resources/test/fixtures/pyflakes/F821_15.py", true, true), ("crates/ruff_linter/resources/test/fixtures/pyflakes/F821_14.py", false, true), ];