From b059dce2523606f1a36c73b25d876d2066dfd20f Mon Sep 17 00:00:00 2001 From: Gergo Magyar Date: Mon, 20 Apr 2026 12:12:24 +0100 Subject: [PATCH] feat(python-scope): 3-var flat destructuring for enumerate(d.items()) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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. --- .../core/ingestion/languages/python/query.ts | 18 ++++++++++++++++++ .../core/ingestion/languages/python/scopes.scm | 16 ++++++++++++++++ 2 files changed, 34 insertions(+) diff --git a/gitnexus/src/core/ingestion/languages/python/query.ts b/gitnexus/src/core/ingestion/languages/python/query.ts index fa6e07687..bd4f73a30 100644 --- a/gitnexus/src/core/ingestion/languages/python/query.ts +++ b/gitnexus/src/core/ingestion/languages/python/query.ts @@ -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 diff --git a/gitnexus/src/core/ingestion/languages/python/scopes.scm b/gitnexus/src/core/ingestion/languages/python/scopes.scm index 2961a0eeb..c57ccb67f 100644 --- a/gitnexus/src/core/ingestion/languages/python/scopes.scm +++ b/gitnexus/src/core/ingestion/languages/python/scopes.scm @@ -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