feat(python-scope): 3-var flat destructuring for enumerate(d.items())

Adds the \`for i, k, v in enumerate(d.items())\` shape — flat
3-variable destructuring of the (i, (k, v)) tuple yielded by
\`enumerate\` over \`items()\`. Binds v (the last identifier in the
pattern_list) to the dict identifier; the existing dict-aware
stripGeneric unwraps to the value type.

Verification:
- Flag-off: 191/191 (identical baseline).
- Flag-on: 4 fail / 187 pass (was 5/186; +1).
- tsc --noEmit clean.
This commit is contained in:
Gergo Magyar 2026-04-20 12:12:24 +01:00
parent f226478ee1
commit b059dce252
2 changed files with 34 additions and 0 deletions

View file

@ -185,6 +185,24 @@ export const PYTHON_SCOPE_QUERY = `
(#eq? @_enum "enumerate")
(#eq? @_items "items")) @type-binding.alias
;; for i, k, v in enumerate(d.items()) 3-var flat destructuring of
;; the (i, (k,v)) tuple emitted by enumerate over items(). Bind v
;; (last id) to d.
(for_statement
left: (pattern_list
(identifier)
(identifier)
(identifier) @type-binding.name)
right: (call
function: (identifier) @_enum
arguments: (argument_list
(call
function: (attribute
object: (identifier) @type-binding.type
attribute: (identifier) @_items))))
(#eq? @_enum "enumerate")
(#eq? @_items "items")) @type-binding.alias
;; for v in d.values() bind v to d (dict-strip yields value type).
(for_statement
left: (identifier) @type-binding.name

View file

@ -197,6 +197,22 @@
(#eq? @_enum "enumerate")
(#eq? @_items "items")) @type-binding.alias
; for i, k, v in enumerate(d.items()) — 3-var flat destructuring.
(for_statement
left: (pattern_list
(identifier)
(identifier)
(identifier) @type-binding.name)
right: (call
function: (identifier) @_enum
arguments: (argument_list
(call
function: (attribute
object: (identifier) @type-binding.type
attribute: (identifier) @_items))))
(#eq? @_enum "enumerate")
(#eq? @_items "items")) @type-binding.alias
; for v in d.values() — bind v to d (dict-strip yields value type).
(for_statement
left: (identifier) @type-binding.name