diff --git a/gitnexus/src/core/ingestion/languages/python/query.ts b/gitnexus/src/core/ingestion/languages/python/query.ts index abfd43766..4732340cc 100644 --- a/gitnexus/src/core/ingestion/languages/python/query.ts +++ b/gitnexus/src/core/ingestion/languages/python/query.ts @@ -108,6 +108,17 @@ export const PYTHON_SCOPE_QUERY = ` left: (identifier) @type-binding.name right: (identifier) @type-binding.type) @type-binding.alias +;; For-loop iterable of a free-call result: +;; def get_users() -> list[User]: ... +;; for u in get_users(): # u: get_users → User via chain follow +;; u.save() +;; Captures the call's function identifier as the rawName. With +;; \`propagateImportedReturnTypes\`, this works cross-file too. +(for_statement + left: (identifier) @type-binding.name + right: (call + function: (identifier) @type-binding.type)) @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 c92d0ee67..69ca6c59c 100644 --- a/gitnexus/src/core/ingestion/languages/python/scopes.scm +++ b/gitnexus/src/core/ingestion/languages/python/scopes.scm @@ -125,6 +125,15 @@ left: (identifier) @type-binding.name type: (type) @type-binding.type) @type-binding.annotation +; For-loop iterable of a free-call result: `for u in get_users()` — +; binds `u → get_users` so the chain post-pass follows it through +; `get_users`'s return-type annotation (cross-file via +; `propagateImportedReturnTypes`). +(for_statement + left: (identifier) @type-binding.name + right: (call + function: (identifier) @type-binding.type)) @type-binding.alias + ; ─── Type bindings: function return-type annotations ───────────────────── ; ; `def get_user() -> User:` — binds the function's NAME to its return