/ queries / python / scopes.scm
scopes.scm
 1  ;; ═════════════════════════════════════════════════════════════════
 2  ;; Python Scope Node Queries
 3  ;; ═════════════════════════════════════════════════════════════════
 4  ;; These patterns identify nodes that create new lexical scopes.
 5  ;; Used for building the scope hierarchy in the BindingGraph.
 6  
 7  ;; ───────────────────────────────────────────────────────────────────
 8  ;; Functions (create function scope)
 9  ;; ───────────────────────────────────────────────────────────────────
10  (function_definition) @scope_node
11  
12  ;; ───────────────────────────────────────────────────────────────────
13  ;; Classes (create class scope)
14  ;; ───────────────────────────────────────────────────────────────────
15  (class_definition) @scope_node
16  
17  ;; ───────────────────────────────────────────────────────────────────
18  ;; Comprehensions (create implicit scope in Python 3)
19  ;; ───────────────────────────────────────────────────────────────────
20  (list_comprehension) @scope_node
21  (dictionary_comprehension) @scope_node
22  (set_comprehension) @scope_node
23  (generator_expression) @scope_node
24  
25  ;; ───────────────────────────────────────────────────────────────────
26  ;; Lambda (creates function scope)
27  ;; ───────────────────────────────────────────────────────────────────
28  (lambda) @scope_node
29  
30  ;; ───────────────────────────────────────────────────────────────────
31  ;; Control flow (for tracking variable positions)
32  ;; Note: Python doesn't have block scope like JS, but we track
33  ;; these for position-based lookups
34  ;; ───────────────────────────────────────────────────────────────────
35  (for_statement) @scope_node
36  (while_statement) @scope_node
37  (if_statement) @scope_node
38  (try_statement) @scope_node
39  (with_statement) @scope_node
40  (match_statement) @scope_node