diff --git a/crates/red_knot_python_semantic/src/types/infer.rs b/crates/red_knot_python_semantic/src/types/infer.rs index 1b33798a96d53..4d3bab3978b2c 100644 --- a/crates/red_knot_python_semantic/src/types/infer.rs +++ b/crates/red_knot_python_semantic/src/types/infer.rs @@ -2289,7 +2289,16 @@ impl<'db> TypeInferenceBuilder<'db> { // (`Type::format`?) that handles the `__format__` method. // Conversion flags should be handled before calling `__format__`. // https://docs.python.org/3/library/string.html#format-string-syntax - if !conversion.is_none() || format_spec.is_some() { + if !conversion.is_none() { + collector.add_expression(); + } else if let Some(ref format_spec) = format_spec { + for element in &format_spec.elements { + if let ast::FStringElement::Expression(expression) = element + { + self.infer_expression(&expression.expression); + } + } + collector.add_expression(); } else { if let Type::StringLiteral(literal) = ty.str(self.db) { diff --git a/crates/red_knot_workspace/tests/check.rs b/crates/red_knot_workspace/tests/check.rs index 8aae30b2618aa..0a2ad2f426f60 100644 --- a/crates/red_knot_workspace/tests/check.rs +++ b/crates/red_knot_workspace/tests/check.rs @@ -283,9 +283,7 @@ const KNOWN_FAILURES: &[(&str, bool, bool)] = &[ ("crates/ruff_linter/resources/test/fixtures/pyflakes/F821_20.py", true, true), ("crates/ruff_linter/resources/test/fixtures/pyflakes/F821_26.py", true, false), // Fails for unknown reasons: - ("crates/ruff_linter/resources/test/fixtures/pyflakes/F541.py", true, true), ("crates/ruff_linter/resources/test/fixtures/pyflakes/F632.py", true, true), ("crates/ruff_linter/resources/test/fixtures/pyflakes/F811_19.py", true, false), ("crates/ruff_linter/resources/test/fixtures/pyupgrade/UP039.py", true, false), - ("crates/ruff_python_parser/resources/valid/expressions/f_string.py", true, true), ];