Skip to content

Commit 1296a09

Browse files
committed
chore: indent test examples + add more nodes for scope creation
1 parent 7a8ec13 commit 1296a09

2 files changed

Lines changed: 32 additions & 19 deletions

File tree

analysis/py_scope.go

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,8 @@ var PyScopeNodes = []string{
3939
"except_clause",
4040
"list_comprehension",
4141
"dictionary_comprehension",
42+
"set_comprehension",
43+
"generator_expression",
4244
"lambda",
4345
}
4446

@@ -89,6 +91,17 @@ func (py *PyScopeBuilder) scanDecl(idOrPattern, declarator *sitter.Node, decls [
8991
})
9092
}
9193
}
94+
95+
case "list_splat_pattern":
96+
splatNode := ChildrenOfType(idOrPattern, "identifier")
97+
splatId := splatNode[0].Child(0)
98+
if splatId.Type() == "identifier" {
99+
decls = append(decls, &Variable{
100+
Kind: VarKindVariable,
101+
Name: splatId.Content(py.source),
102+
DeclNode: declarator,
103+
})
104+
}
92105
}
93106

94107
return decls

analysis/py_scope_test.go

Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,10 @@ func parsePyFile(t *testing.T, source string) *ParseResult {
1717
func Test_PyBuildScopeTree(t *testing.T) {
1818
t.Run("is able to resolve references", func(t *testing.T) {
1919
source := `
20-
x = 1
21-
if True:
22-
y = x
23-
z = x`
20+
x = 1
21+
if True:
22+
y = x
23+
z = x`
2424
parsed := parsePyFile(t, source)
2525

2626
scopeTree := MakeScopeTree(parsed.Language, parsed.Ast, parsed.Source)
@@ -47,14 +47,14 @@ func Test_PyBuildScopeTree(t *testing.T) {
4747

4848
t.Run("supports import statements", func(t *testing.T) {
4949
source := `
50-
import os
50+
import os
5151
52-
os.system("cat file.txt")
52+
os.system("cat file.txt")
5353
54-
from csv import read
54+
from csv import read
5555
56-
if True:
57-
f = read(file.csv)
56+
if True:
57+
f = read(file.csv)
5858
`
5959
parsed := parsePyFile(t, source)
6060

@@ -96,10 +96,10 @@ func Test_PyBuildScopeTree(t *testing.T) {
9696

9797
t.Run("supports function parameters", func(t *testing.T) {
9898
source := `
99-
def myFunc(a, b=2, c:int, d:str="Hello"):
100-
A = otherFunc(a)
101-
C = b + c
102-
print(d)
99+
def myFunc(a, b=2, c:int, d:str="Hello"):
100+
A = otherFunc(a)
101+
C = b + c
102+
print(d)
103103
`
104104
parsed := parsePyFile(t, source)
105105

@@ -144,8 +144,8 @@ func Test_PyBuildScopeTree(t *testing.T) {
144144

145145
t.Run("supports with statements", func(t *testing.T) {
146146
source := `
147-
with open("file.txt", 'r') as f:
148-
print(f.read(5))
147+
with open("file.txt", 'r') as f:
148+
print(f.read(5))
149149
`
150150
parsed := parsePyFile(t, source)
151151

@@ -280,10 +280,10 @@ a = lambda x: x**2
280280

281281
t.Run("supports exception statements", func(t *testing.T) {
282282
source := `
283-
try:
284-
result = 10 / 2
285-
except ZeroDivisionError as e:
286-
print(e)
283+
try:
284+
result = 10 / 2
285+
except ZeroDivisionError as e:
286+
print(e)
287287
`
288288
parsed := parsePyFile(t, source)
289289

0 commit comments

Comments
 (0)