Skip to content

Commit

Permalink
fix(python): import statements (#1623)
Browse files Browse the repository at this point in the history
  • Loading branch information
elsapet committed Jun 6, 2024
1 parent a23c509 commit 6c3035a
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 1 deletion.
3 changes: 3 additions & 0 deletions pkg/languages/python/analyzer/analyzer.go
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,9 @@ func (analyzer *analyzer) analyzeAssignment(node *sitter.Node, visitChildren fun
// foo.bar(a, b)
func (analyzer *analyzer) analyzeCall(node *sitter.Node, visitChildren func() error) error {
if function := node.ChildByFieldName("function"); function != nil {
analyzer.lookupVariable(function)
analyzer.builder.Dataflow(function)

object := function.ChildByFieldName("object")
analyzer.lookupVariable(object)

Expand Down
4 changes: 3 additions & 1 deletion pkg/languages/python/testdata/import/import.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,4 +35,6 @@

import FooClass as SomethingElse
y = SomethingElse()
y.qwerty()
y.qwerty()

foo()
5 changes: 5 additions & 0 deletions pkg/languages/python/testdata/import_rule.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
languages:
- python
patterns:
- pattern: $<IMPORT_FROM>($<...>)
filters:
- variable: IMPORT_FROM
detection: import_test_import_from
scope: result
- pattern: $<IMPORT_FROM>.someMethod($<...>)
filters:
- variable: IMPORT_FROM
Expand Down

0 comments on commit 6c3035a

Please sign in to comment.