diff --git a/crates/ruff_python_parser/src/lexer.rs b/crates/ruff_python_parser/src/lexer.rs index 834f4b4f360228..394451cd6eef09 100644 --- a/crates/ruff_python_parser/src/lexer.rs +++ b/crates/ruff_python_parser/src/lexer.rs @@ -2022,6 +2022,16 @@ allowed {x}"""} string""#; assert_debug_snapshot!(lex_source(source)); } + #[test] + fn test_fstring_with_lambda_expression() { + let source = r#" +f"{lambda x:{x}}" +f"{(lambda x:{x})}" +"# + .trim(); + assert_debug_snapshot!(lex_source(source)); + } + fn lex_fstring_error(source: &str) -> FStringErrorType { match lex(source, Mode::Module).find_map(std::result::Result::err) { Some(err) => match err.error { diff --git a/crates/ruff_python_parser/src/snapshots/ruff_python_parser__lexer__tests__fstring_with_lambda_expression.snap b/crates/ruff_python_parser/src/snapshots/ruff_python_parser__lexer__tests__fstring_with_lambda_expression.snap new file mode 100644 index 00000000000000..d30d9bc63f7127 --- /dev/null +++ b/crates/ruff_python_parser/src/snapshots/ruff_python_parser__lexer__tests__fstring_with_lambda_expression.snap @@ -0,0 +1,42 @@ +--- +source: crates/ruff_python_parser/src/lexer.rs +expression: lex_source(source) +--- +[ + FStringStart, + Lbrace, + Lambda, + Name { + name: "x", + }, + Colon, + Lbrace, + Name { + name: "x", + }, + Rbrace, + FStringMiddle { + value: "", + is_raw: false, + }, + Rbrace, + FStringEnd, + Newline, + FStringStart, + Lbrace, + Lpar, + Lambda, + Name { + name: "x", + }, + Colon, + Lbrace, + Name { + name: "x", + }, + Rbrace, + Rpar, + Rbrace, + FStringEnd, + Newline, +]