Python: Consolidate duplicated code

This commit is contained in:
Taus
2026-04-16 21:14:42 +00:00
parent 8b1ecf05c9
commit 6c675fcede

View File

@@ -795,12 +795,7 @@
;;;;;; DictComp (`{a: b for c in d if e}`)
; See GeneratorExp for details.
(dictionary_comprehension
body: (pair
key: (_) @_key
value: (_) @_value
)
) @genexpr
(dictionary_comprehension) @genexpr
{
; Synthesize the `genexpr` function
let @genexpr.fun = (ast-node @genexpr "Function")
@@ -824,29 +819,6 @@
attr (@genexpr.arg_use) ctx = "load"
}
; DictComp with unpacking (PEP 798): `{**d for d in dicts}`
(dictionary_comprehension
body: (dictionary_splat)
) @genexpr
{
let @genexpr.fun = (ast-node @genexpr "Function")
attr (@genexpr.node) function = @genexpr.fun
attr (@genexpr.fun) name = "dictcomp"
let @genexpr.arg = (ast-node @genexpr "Name")
attr (@genexpr.arg) variable = ".0"
attr (@genexpr.arg) ctx = "param"
edge @genexpr.fun -> @genexpr.arg
attr (@genexpr.fun -> @genexpr.arg) args = 0
attr (@genexpr.fun) kwonlyargs = #null
attr (@genexpr.fun) kwarg = #null
let @genexpr.arg_use = (ast-node @genexpr "Name")
attr (@genexpr.arg_use) variable = ".0"
attr (@genexpr.arg_use) ctx = "load"
}
;;;;;; End of DictComp (`{a: b for c in d if e}`)
;;;;;; GeneratorExp (`(a for b in c if d)`)