Skip to content

Commit 8b6b4dd

Browse files
authored
Python: Refactor built-ins logic
This will make it possible to reuse for names defined in `import *`.
1 parent df8a6b9 commit 8b6b4dd

File tree

1 file changed

+12
-7
lines changed

1 file changed

+12
-7
lines changed

python/ql/src/semmle/python/ApiGraphs.qll

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -424,13 +424,8 @@ module API {
424424
* a value in the module `m`.
425425
*/
426426
private predicate possible_builtin_defined_in_module(string name, Module m) {
427-
exists(NameNode n |
428-
not exists(LocalVariable v | n.defines(v)) and
429-
n.isStore() and
430-
name = n.getId() and
431-
name = getBuiltInName() and
432-
m = n.getEnclosingModule()
433-
)
427+
global_name_defined_in_module(name, m) and
428+
name = getBuiltInName()
434429
}
435430

436431
/**
@@ -445,6 +440,16 @@ module API {
445440
m = n.getEnclosingModule()
446441
}
447442

443+
/** Holds if a global variable called `name` is assigned a value in the module `m`. */
444+
private predicate global_name_defined_in_module(string name, Module m) {
445+
exists(NameNode n |
446+
not exists(LocalVariable v | n.defines(v)) and
447+
n.isStore() and
448+
name = n.getId() and
449+
m = n.getEnclosingModule()
450+
)
451+
}
452+
448453
/**
449454
* Holds if `ref` is a use of a node that should have an incoming edge from `base` labeled
450455
* `lbl` in the API graph.

0 commit comments

Comments
 (0)