diff --git a/gitnexus/src/core/ingestion/languages/python/query.ts b/gitnexus/src/core/ingestion/languages/python/query.ts index b5f7a0d0e..fa6e07687 100644 --- a/gitnexus/src/core/ingestion/languages/python/query.ts +++ b/gitnexus/src/core/ingestion/languages/python/query.ts @@ -167,6 +167,33 @@ export const PYTHON_SCOPE_QUERY = ` attribute: (identifier) @_items)) (#eq? @_items "items")) @type-binding.alias +;; for i, (k, v) in enumerate(d.items()) — nested tuple destructuring. +;; Bind v (last id of the nested tuple) to d (the dict). +(for_statement + left: (pattern_list + (identifier) + (tuple_pattern + (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 + right: (call + function: (attribute + object: (identifier) @type-binding.type + attribute: (identifier) @_values)) + (#eq? @_values "values")) @type-binding.alias + ;; Type bindings (variable annotations: \`u: User\` / \`u: User = x\`) (assignment 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 f30907819..2961a0eeb 100644 --- a/gitnexus/src/core/ingestion/languages/python/scopes.scm +++ b/gitnexus/src/core/ingestion/languages/python/scopes.scm @@ -180,6 +180,32 @@ attribute: (identifier) @_items)) (#eq? @_items "items")) @type-binding.alias +; for i, (k, v) in enumerate(d.items()) — nested tuple destructuring. +(for_statement + left: (pattern_list + (identifier) + (tuple_pattern + (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 + right: (call + function: (attribute + object: (identifier) @type-binding.type + attribute: (identifier) @_values)) + (#eq? @_values "values")) @type-binding.alias + ; ─── Type bindings: function return-type annotations ───────────────────── ; ; `def get_user() -> User:` — binds the function's NAME to its return