diff --git a/crates/ruff_python_parser/src/parser/snapshots/ruff_python_parser__parser__tests__dict_double_star_missing_left_operand.snap b/crates/ruff_python_parser/src/parser/snapshots/ruff_python_parser__parser__tests__dict_double_star_missing_left_operand.snap new file mode 100644 index 0000000000..b2761a29a9 --- /dev/null +++ b/crates/ruff_python_parser/src/parser/snapshots/ruff_python_parser__parser__tests__dict_double_star_missing_left_operand.snap @@ -0,0 +1,108 @@ +--- +source: crates/ruff_python_parser/src/parser/tests.rs +expression: result +--- +Parsed { + syntax: ModExpression { + node_index: NodeIndex(None), + range: 0..25, + body: DictComp( + ExprDictComp { + node_index: NodeIndex(None), + range: 0..25, + key: Name( + ExprName { + node_index: NodeIndex(None), + range: 1..2, + id: Name("x"), + ctx: Load, + }, + ), + value: BinOp( + ExprBinOp { + node_index: NodeIndex(None), + range: 4..7, + left: Name( + ExprName { + node_index: NodeIndex(None), + range: 7..7, + id: Name(""), + ctx: Invalid, + }, + ), + op: Pow, + right: Name( + ExprName { + node_index: NodeIndex(None), + range: 6..7, + id: Name("y"), + ctx: Load, + }, + ), + }, + ), + generators: [ + Comprehension { + range: 8..24, + node_index: NodeIndex(None), + target: Tuple( + ExprTuple { + node_index: NodeIndex(None), + range: 12..16, + elts: [ + Name( + ExprName { + node_index: NodeIndex(None), + range: 12..13, + id: Name("x"), + ctx: Store, + }, + ), + Name( + ExprName { + node_index: NodeIndex(None), + range: 15..16, + id: Name("y"), + ctx: Store, + }, + ), + ], + ctx: Store, + parenthesized: false, + }, + ), + iter: Name( + ExprName { + node_index: NodeIndex(None), + range: 20..24, + id: Name("data"), + ctx: Load, + }, + ), + ifs: [], + is_async: false, + }, + ], + }, + ), + }, + tokens: Tokens { + raw: [ + Lbrace 0..1, + Name 1..2, + Colon 2..3, + DoubleStar 4..6, + Name 6..7, + For 8..11, + Name 12..13, + Comma 13..14, + Name 15..16, + In 17..19, + Name 20..24, + Rbrace 24..25, + Newline 25..25, + ], + }, + errors: [], + unsupported_syntax_errors: [], +} diff --git a/crates/ruff_python_parser/src/parser/snapshots/ruff_python_parser__parser__tests__function_kwargs.snap b/crates/ruff_python_parser/src/parser/snapshots/ruff_python_parser__parser__tests__function_kwargs.snap new file mode 100644 index 0000000000..4221c61a77 --- /dev/null +++ b/crates/ruff_python_parser/src/parser/snapshots/ruff_python_parser__parser__tests__function_kwargs.snap @@ -0,0 +1,56 @@ +--- +source: crates/ruff_python_parser/src/parser/tests.rs +expression: result +--- +Parsed { + syntax: ModExpression { + node_index: NodeIndex(None), + range: 0..13, + body: Call( + ExprCall { + node_index: NodeIndex(None), + range: 0..13, + func: Name( + ExprName { + node_index: NodeIndex(None), + range: 0..3, + id: Name("foo"), + ctx: Load, + }, + ), + arguments: Arguments { + range: 3..13, + node_index: NodeIndex(None), + args: [], + keywords: [ + Keyword { + range: 4..12, + node_index: NodeIndex(None), + arg: None, + value: Name( + ExprName { + node_index: NodeIndex(None), + range: 6..12, + id: Name("kwargs"), + ctx: Load, + }, + ), + }, + ], + }, + }, + ), + }, + tokens: Tokens { + raw: [ + Name 0..3, + Lpar 3..4, + DoubleStar 4..6, + Name 6..12, + Rpar 12..13, + Newline 13..13, + ], + }, + errors: [], + unsupported_syntax_errors: [], +} diff --git a/crates/ruff_python_parser/src/parser/tests.rs b/crates/ruff_python_parser/src/parser/tests.rs index dcb9ac16a0..05227b1bf4 100644 --- a/crates/ruff_python_parser/src/parser/tests.rs +++ b/crates/ruff_python_parser/src/parser/tests.rs @@ -157,3 +157,21 @@ t"i}'"#; insta::assert_debug_snapshot!(error); } + +#[test] +fn test_dict_double_star_missing_left_operand() { + let source = r#"{x: **y for x, y in data}"#; + let parsed = parse_expression(source); + assert!(parsed.is_ok()); + let result = parsed.unwrap(); + insta::assert_debug_snapshot!(result); +} + +#[test] +fn test_function_kwargs() { + let source = r#"foo(**kwargs)"#; + let parsed = parse_expression(source); + assert!(parsed.is_ok()); + let result = parsed.unwrap(); + insta::assert_debug_snapshot!(result); +}