@@ -28,14 +28,14 @@ predicate probablySingleton(ClassValue cls) {
28
28
29
29
predicate invalid_to_use_is_portably ( ClassValue c ) {
30
30
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__
32
32
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
34
34
not probablySingleton ( c )
35
35
}
36
36
37
37
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" ) )
39
39
}
40
40
41
41
private predicate cpython_interned_value ( Expr e ) {
@@ -66,14 +66,14 @@ private predicate universally_interned_value(Expr e) {
66
66
67
67
predicate cpython_interned_constant ( Expr e ) {
68
68
exists ( Expr const |
69
- e .refersTo ( _, const ) |
69
+ e .pointsTo ( _, const ) |
70
70
cpython_interned_value ( const )
71
71
)
72
72
}
73
73
74
74
predicate universally_interned_constant ( Expr e ) {
75
75
exists ( Expr const |
76
- e .refersTo ( _, const ) |
76
+ e .pointsTo ( _, const ) |
77
77
universally_interned_value ( const )
78
78
)
79
79
}
@@ -95,7 +95,7 @@ private predicate comparison_one_type(Compare comp, Cmpop op, ClassValue cls) {
95
95
}
96
96
97
97
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__'
99
99
not exists ( Function eq | eq .getName ( ) = "__eq__" or eq .getName ( ) = "__ne__" | eq = comp .getScope ( ) .getScope * ( ) )
100
100
and
101
101
(
@@ -107,24 +107,24 @@ predicate invalid_portable_is_comparison(Compare comp, Cmpop op, ClassValue cls)
107
107
)
108
108
)
109
109
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 |
112
112
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 )
115
115
or
116
- /* Simple constant in module, probably some sort of sentinel */
116
+ // Simple constant in module, probably some sort of sentinel
117
117
exists ( AstNode origin |
118
- not left .refersTo ( _) and right .refersTo ( obj , origin ) and
118
+ not left .pointsTo ( _) and right .pointsTo ( val , origin ) and
119
119
origin .getScope ( ) .getEnclosingModule ( ) = comp .getScope ( ) .getEnclosingModule ( )
120
120
)
121
121
)
122
122
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
124
124
not exists ( Expr left , Expr right , AstNode origin |
125
125
comp .compares ( left , op , right ) and
126
126
enum_member ( origin ) |
127
- left .refersTo ( _, origin ) or right .refersTo ( _, origin )
127
+ left .pointsTo ( _, origin ) or right .pointsTo ( _, origin )
128
128
)
129
129
}
130
130
@@ -135,4 +135,3 @@ private predicate enum_member(AstNode obj) {
135
135
asgn .getValue ( ) = obj
136
136
)
137
137
}
138
-
0 commit comments