From 4b5ff0b89ee4e220f3bf4bd2e77b2b6426da3752 Mon Sep 17 00:00:00 2001 From: Taus Date: Fri, 10 Apr 2026 15:52:33 +0000 Subject: [PATCH] Python: Support unpacking in comprehensions in `tree-sitter-python` This is the easy part -- we just allow `dictionary_splat` or `list_splat` to appear in the same place as the expression. --- python/extractor/tsg-python/tsp/grammar.js | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/python/extractor/tsg-python/tsp/grammar.js b/python/extractor/tsg-python/tsp/grammar.js index 05b792340dd..8f4dd8d7cf6 100644 --- a/python/extractor/tsg-python/tsp/grammar.js +++ b/python/extractor/tsg-python/tsp/grammar.js @@ -1031,28 +1031,28 @@ module.exports = grammar({ list_comprehension: $ => seq( '[', - field('body', $.expression), + field('body', choice($.expression, $.list_splat)), $._comprehension_clauses, ']' ), dictionary_comprehension: $ => seq( '{', - field('body', $.pair), + field('body', choice($.pair, $.dictionary_splat)), $._comprehension_clauses, '}' ), set_comprehension: $ => seq( '{', - field('body', $.expression), + field('body', choice($.expression, $.list_splat)), $._comprehension_clauses, '}' ), generator_expression: $ => seq( '(', - field('body', $.expression), + field('body', choice($.expression, $.list_splat)), $._comprehension_clauses, ')' ),