Skip to content

Commit 75a43e7

Browse files
authored
Python: Address review comments.
- Removes the version check on the set of built-in names. - Renames the predicate used to represent said set. - Documents how these lists of names were obtained. - Gets rid of a superfluous import.
1 parent 79cfe5a commit 75a43e7

File tree

1 file changed

+6
-8
lines changed

1 file changed

+6
-8
lines changed

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

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -349,10 +349,10 @@ module API {
349349
)
350350
}
351351

352-
private import semmle.python.types.Builtins as Builtins
353-
354-
/** Returns the names of known built-ins. */
355-
private string builtin_name() {
352+
/** Gets the name of a known built-in. */
353+
private string getBuiltInName() {
354+
// These lists were created by inspecting the `builtins` and `__builtin__` modules in
355+
// Python 2 and 3 respectively, using the `dir` built-in.
356356
// Built-in functions and exceptions shared between Python 2 and 3
357357
result in [
358358
"abs", "all", "any", "bin", "bool", "bytearray", "callable", "chr", "classmethod",
@@ -381,7 +381,6 @@ module API {
381381
result in ["False", "True", "None", "NotImplemented", "Ellipsis", "__debug__"]
382382
or
383383
// Python 3 only
384-
major_version() = 3 and
385384
result in [
386385
"ascii", "breakpoint", "bytes", "exec",
387386
// Exceptions
@@ -393,7 +392,6 @@ module API {
393392
]
394393
or
395394
// Python 2 only
396-
major_version() = 2 and
397395
result in [
398396
"basestring", "cmp", "execfile", "file", "long", "raw_input", "reduce", "reload",
399397
"unichr", "unicode", "xrange"
@@ -425,7 +423,7 @@ module API {
425423
not exists(LocalVariable v | n.defines(v)) and
426424
n.isStore() and
427425
name = n.getId() and
428-
name = builtin_name() and
426+
name = getBuiltInName() and
429427
m = n.getEnclosingModule()
430428
)
431429
}
@@ -438,7 +436,7 @@ module API {
438436
n.isGlobal() and
439437
n.isLoad() and
440438
name = n.getId() and
441-
name = builtin_name() and
439+
name = getBuiltInName() and
442440
m = n.getEnclosingModule()
443441
}
444442

0 commit comments

Comments
 (0)