Skip to content

Commit 464a034

Browse files
authored
Merge pull request github#2894 from BekaValentine/python-objectapi-to-valueapi-iscomparisons
Python: ObjectAPI to ValueAPI: IsComparisons
2 parents a576f3f + 9601c41 commit 464a034

File tree

1 file changed

+14
-15
lines changed

1 file changed

+14
-15
lines changed

python/ql/src/Expressions/IsComparisons.qll

Lines changed: 14 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -28,14 +28,14 @@ predicate probablySingleton(ClassValue cls) {
2828

2929
predicate invalid_to_use_is_portably(ClassValue c) {
3030
overrides_eq_or_cmp(c) and
31-
/* Exclude type/builtin-function/bool as it is legitimate to compare them using 'is' but they implement __eq__ */
31+
// Exclude type/builtin-function/bool as it is legitimate to compare them using 'is' but they implement __eq__
3232
not c = Value::named("type") and not c = ClassValue::builtinFunction() and not c = Value::named("bool") and
33-
/* OK to compare with 'is' if a singleton */
33+
// OK to compare with 'is' if a singleton
3434
not probablySingleton(c)
3535
}
3636

3737
predicate simple_constant(ControlFlowNode f) {
38-
exists(Object obj | f.refersTo(obj) | obj = theTrueObject() or obj = theFalseObject() or obj = theNoneObject())
38+
exists(Value val | f.pointsTo(val) | val = Value::named("True") or val = Value::named("False") or val = Value::named("None"))
3939
}
4040

4141
private predicate cpython_interned_value(Expr e) {
@@ -66,14 +66,14 @@ private predicate universally_interned_value(Expr e) {
6666

6767
predicate cpython_interned_constant(Expr e) {
6868
exists(Expr const |
69-
e.refersTo(_, const) |
69+
e.pointsTo(_, const) |
7070
cpython_interned_value(const)
7171
)
7272
}
7373

7474
predicate universally_interned_constant(Expr e) {
7575
exists(Expr const |
76-
e.refersTo(_, const) |
76+
e.pointsTo(_, const) |
7777
universally_interned_value(const)
7878
)
7979
}
@@ -95,7 +95,7 @@ private predicate comparison_one_type(Compare comp, Cmpop op, ClassValue cls) {
9595
}
9696

9797
predicate invalid_portable_is_comparison(Compare comp, Cmpop op, ClassValue cls) {
98-
/* OK to use 'is' when defining '__eq__' */
98+
// OK to use 'is' when defining '__eq__'
9999
not exists(Function eq | eq.getName() = "__eq__" or eq.getName() = "__ne__" | eq = comp.getScope().getScope*())
100100
and
101101
(
@@ -107,24 +107,24 @@ predicate invalid_portable_is_comparison(Compare comp, Cmpop op, ClassValue cls)
107107
)
108108
)
109109
and
110-
/* OK to use 'is' when comparing items from a known set of objects */
111-
not exists(Expr left, Expr right, Object obj |
110+
// OK to use 'is' when comparing items from a known set of objects
111+
not exists(Expr left, Expr right, Value val |
112112
comp.compares(left, op, right) and
113-
exists(ImmutableLiteral il | il.getLiteralObject() = obj) |
114-
left.refersTo(obj) and right.refersTo(obj)
113+
exists(ImmutableLiteral il | il.getLiteralValue() = val) |
114+
left.pointsTo(val) and right.pointsTo(val)
115115
or
116-
/* Simple constant in module, probably some sort of sentinel */
116+
// Simple constant in module, probably some sort of sentinel
117117
exists(AstNode origin |
118-
not left.refersTo(_) and right.refersTo(obj, origin) and
118+
not left.pointsTo(_) and right.pointsTo(val, origin) and
119119
origin.getScope().getEnclosingModule() = comp.getScope().getEnclosingModule()
120120
)
121121
)
122122
and
123-
/* OK to use 'is' when comparing with a member of an enum */
123+
// OK to use 'is' when comparing with a member of an enum
124124
not exists(Expr left, Expr right, AstNode origin |
125125
comp.compares(left, op, right) and
126126
enum_member(origin) |
127-
left.refersTo(_, origin) or right.refersTo(_, origin)
127+
left.pointsTo(_, origin) or right.pointsTo(_, origin)
128128
)
129129
}
130130

@@ -135,4 +135,3 @@ private predicate enum_member(AstNode obj) {
135135
asgn.getValue() = obj
136136
)
137137
}
138-

0 commit comments

Comments
 (0)