Skip to content

Commit 2d771df

Browse files
committed
update
1 parent 0fbd18d commit 2d771df

File tree

1 file changed

+8
-8
lines changed

1 file changed

+8
-8
lines changed

gazelle/python/file_parser.go

+8-8
Original file line numberDiff line numberDiff line change
@@ -165,19 +165,19 @@ func (p *FileParser) parseImportStatements(node *sitter.Node) bool {
165165
}
166166
} else if node.Type() == sitterNodeTypeImportFromStatement {
167167
from := node.Child(1).Content(p.code)
168+
// If the import is from the current package, we don't need to add it to the modules.
169+
// If the import is from a different relative package i.e. from .package1 import foo, we need to add it to the modules.
170+
if from == "." {
171+
return true
172+
}
168173
for j := 3; j < int(node.ChildCount()); j++ {
169174
m, ok := parseImportStatement(node.Child(j), p.code)
170175
if !ok {
171176
continue
172177
}
173-
m.Filepath = p.relFilepath
174-
175-
if from == "." {
176-
return true
177-
} else {
178-
m.From = from
179-
m.Name = fmt.Sprintf("%s.%s", from, m.Name)
180-
}
178+
m.Filepath = p.relFilepath{
179+
m.From = from
180+
m.Name = fmt.Sprintf("%s.%s", from, m.Name)
181181
p.output.Modules = append(p.output.Modules, m)
182182
}
183183
} else {

0 commit comments

Comments
 (0)