Skip to content

Commit 5736892

Browse files
committed
Python: Fix Builtin.isClass() and use in ClassObject. Also fix a couple of typos.
1 parent 9d31d09 commit 5736892

File tree

3 files changed

+6
-5
lines changed

3 files changed

+6
-5
lines changed

python/ql/src/semmle/python/types/Builtins.qll

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ class Builtin extends @py_cobject {
4040
}
4141

4242
Builtin getBaseClass() {
43+
/* The extractor uses the special name ".super." to indicate the super class of a builtin class */
4344
py_cmembers_versioned(this, ".super.", result, major_version().toString())
4445
}
4546

@@ -54,7 +55,9 @@ class Builtin extends @py_cobject {
5455
}
5556

5657
predicate isClass() {
57-
py_cobjecttypes(_, this) or this = Builtin::unknownType()
58+
py_cobjecttypes(_, this) or
59+
this = Builtin::unknownType() or
60+
exists(Builtin meta | meta.inheritsFromType() and py_cobjecttypes(this, meta))
5861
}
5962

6063
predicate isFunction() {

python/ql/src/semmle/python/types/ClassObject.qll

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,9 +22,7 @@ class ClassObject extends Object {
2222

2323
ClassObject() {
2424
this.getOrigin() instanceof ClassExpr or
25-
exists(Builtin o | o.getClass() = this.asBuiltin()) or
26-
this.asBuiltin().getClass().inheritsFromType() or
27-
this.asBuiltin() = Builtin::special("_semmle_unknown_type")
25+
this.asBuiltin().isClass()
2826
}
2927

3028
private predicate isStr() {

python/ql/src/semmle/python/types/Object.qll

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ class Object extends @py_object {
3737
ClassObject getAnInferredType() {
3838
exists(ControlFlowNode somewhere | somewhere.refersTo(this, result, _))
3939
or
40-
this.asBuiltin().getClass() = result.asBuiltin()and not this = unknownValue()
40+
this.asBuiltin().getClass() = result.asBuiltin() and not this = unknownValue()
4141
or
4242
this = unknownValue() and result = theUnknownType()
4343
}

0 commit comments

Comments
 (0)