Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 51e0637

Browse files
authored
Merge pull request #1456 from markshannon/python-remove-value-get-source
Python: Remove Value.getSource(). It has no use.
2 parents 635de7c + 30e1cbc commit 51e0637

13 files changed

Lines changed: 24 additions & 27 deletions

File tree

python/ql/src/semmle/python/Module.qll

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -71,9 +71,9 @@ class Module extends Module_, Scope, AstNode {
7171
string getAnExport() {
7272
py_exports(this, result)
7373
or
74-
exists(ModuleValue mod |
74+
exists(ModuleObjectInternal mod |
7575
mod.getSource() = this.getEntryNode() |
76-
mod.exports(result)
76+
mod.(ModuleValue).exports(result)
7777
)
7878
}
7979

python/ql/src/semmle/python/objects/ObjectAPI.qll

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -71,13 +71,6 @@ class Value extends TObject {
7171
this.(ObjectInternal).attribute(name, result, _)
7272
}
7373

74-
/** DEPRECATED: For backwards compatibility with old API
75-
* Use `Value` instead of `ObjectSource`.
76-
*/
77-
deprecated ObjectSource getSource() {
78-
result = this.(ObjectInternal).getSource()
79-
}
80-
8174
/** Holds if this value is builtin. Applies to built-in functions and methods,
8275
* but also integers and strings.
8376
*/

python/ql/src/semmle/python/pointsto/PointsTo.qll

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -141,7 +141,7 @@ module PointsTo {
141141
)
142142
or
143143
not f.isParameter() and
144-
exists(Value value |
144+
exists(ObjectInternal value |
145145
PointsToInternal::pointsTo(f.(DefinitionNode).getValue(), context, value, origin) and
146146
cls = value.getClass().getSource() |
147147
obj = value.getSource() or
@@ -151,7 +151,7 @@ module PointsTo {
151151

152152
deprecated predicate
153153
ssa_variable_points_to(EssaVariable var, PointsToContext context, Object obj, ClassObject cls, CfgOrigin origin) {
154-
exists(Value value |
154+
exists(ObjectInternal value |
155155
PointsToInternal::variablePointsTo(var, context, value, origin) and
156156
cls = value.getClass().getSource() |
157157
obj = value.getSource()
@@ -160,8 +160,8 @@ module PointsTo {
160160

161161
deprecated
162162
CallNode get_a_call(Object func, PointsToContext context) {
163-
exists(Value value |
164-
result = value.getACall(context) and
163+
exists(ObjectInternal value |
164+
result = value.(Value).getACall(context) and
165165
func = value.getSource()
166166
)
167167
}

python/ql/src/semmle/python/security/TaintTracking.qll

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -144,7 +144,7 @@ abstract class TaintKind extends string {
144144
* the `result` would be `theStrType()`.
145145
*/
146146
ClassValue getType() {
147-
result.getSource() = this.getClass()
147+
result.(ClassObjectInternal).getSource() = this.getClass()
148148
}
149149

150150
/** Gets the boolean values (may be one, neither, or both) that

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

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ private import semmle.python.objects.Instances
44
private import semmle.python.pointsto.PointsTo
55
private import semmle.python.pointsto.MRO
66
private import semmle.python.types.Builtins
7+
private import semmle.python.objects.ObjectInternal
78

89

910
/** A class whose instances represents Python classes.
@@ -99,7 +100,7 @@ class ClassObject extends Object {
99100

100101
/** Returns an attribute declared on this class (not on a super-class) */
101102
Object declaredAttribute(string name) {
102-
exists(Value val |
103+
exists(ObjectInternal val |
103104
Types::declaredAttribute(theClass(), name, val, _) and
104105
result = val.getSource()
105106
)
@@ -113,7 +114,7 @@ class ClassObject extends Object {
113114
/** Returns an attribute as it would be when looked up at runtime on this class.
114115
Will include attributes of super-classes */
115116
Object lookupAttribute(string name) {
116-
exists(Value val |
117+
exists(ObjectInternal val |
117118
theClass().lookup(name, val, _) and
118119
result = val.getSource()
119120
)
@@ -125,7 +126,7 @@ class ClassObject extends Object {
125126

126127
/** Looks up an attribute by searching this class' MRO starting at `start` */
127128
Object lookupMro(ClassObject start, string name) {
128-
exists(ClassObjectInternal other, ClassObjectInternal decl, Value val |
129+
exists(ClassObjectInternal other, ClassObjectInternal decl, ObjectInternal val |
129130
other.getSource() = start and
130131
decl = Types::getMro(theClass()).startingAt(other).findDeclaringClass(name) and
131132
Types::declaredAttribute(decl, name, val, _) and
@@ -140,7 +141,7 @@ class ClassObject extends Object {
140141

141142
/** Whether the named attribute refers to the object, class and origin */
142143
predicate attributeRefersTo(string name, Object obj, ClassObject cls, ControlFlowNode origin) {
143-
exists(Value val, CfgOrigin valorig |
144+
exists(ObjectInternal val, CfgOrigin valorig |
144145
theClass().lookup(name, val, valorig) and
145146
obj = val.getSource() and
146147
cls = val.getClass().getSource() and

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,14 @@ private import semmle.python.pointsto.PointsTo
44
private import semmle.python.objects.Callables
55
private import semmle.python.libraries.Zope
66
private import semmle.python.pointsto.Base
7+
private import semmle.python.objects.ObjectInternal
78
private import semmle.python.types.Builtins
89

910
/** A function object, whether written in Python or builtin */
1011
abstract class FunctionObject extends Object {
1112

1213
CallableValue theCallable() {
13-
result.getSource() = this
14+
result.(ObjectInternal).getSource() = this
1415
}
1516

1617
predicate isOverridingMethod() {

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

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import python
22
private import semmle.python.pointsto.PointsTo
3-
private import semmle.python.objects.Modules
3+
private import semmle.python.objects.ObjectInternal
44
private import semmle.python.types.ModuleKind
55

66
abstract class ModuleObject extends Object {
@@ -57,15 +57,15 @@ abstract class ModuleObject extends Object {
5757
}
5858

5959
predicate attributeRefersTo(string name, Object obj, ControlFlowNode origin) {
60-
exists(Value val, CfgOrigin valorig |
60+
exists(ObjectInternal val, CfgOrigin valorig |
6161
theModule().(ModuleObjectInternal).attribute(name, val, valorig) and
6262
obj = val.getSource() and
6363
origin = valorig.toCfgNode()
6464
)
6565
}
6666

6767
predicate attributeRefersTo(string name, Object obj, ClassObject cls, ControlFlowNode origin) {
68-
exists(Value val, CfgOrigin valorig |
68+
exists(ObjectInternal val, CfgOrigin valorig |
6969
theModule().(ModuleObjectInternal).attribute(name, val, valorig) and
7070
obj = val.getSource() and
7171
cls = val.getClass().getSource() and
@@ -226,7 +226,7 @@ class PackageObject extends ModuleObject {
226226
}
227227

228228
override Object getAttribute(string name) {
229-
exists(Value val |
229+
exists(ObjectInternal val |
230230
theModule().(PackageObjectInternal).attribute(name, val, _) and
231231
result = val.getSource()
232232
)

python/ql/test/3/library-tests/PointsTo/attributes/Test.expected

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
| 1 | ControlFlowNode for unicode_literals | ImportMember | 1 |
12
| 2 | ControlFlowNode for C | class C | 2 |
23
| 2 | ControlFlowNode for ClassExpr | class C | 2 |
34
| 2 | ControlFlowNode for object | builtin-class object | 2 |

python/ql/test/library-tests/PointsTo/general/GlobalPointsTo.expected

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,7 @@
9898
| Module pointsto_test | 76 | ControlFlowNode for sys | Module sys |
9999
| Module pointsto_test | 76 | ControlFlowNode for type | builtin-class type |
100100
| Module pointsto_test | 76 | ControlFlowNode for type() | builtin-class module |
101+
| Module pointsto_test | 77 | ControlFlowNode for unknown | ImportMember |
101102
| Module pointsto_test | 78 | ControlFlowNode for type | builtin-class type |
102103
| Module pointsto_test | 79 | ControlFlowNode for Dict | Dict |
103104
| Module pointsto_test | 79 | ControlFlowNode for Tuple | Tuple |

python/ql/test/library-tests/PointsTo/general/LocalPointsTo.expected

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,7 @@
106106
| 76 | ControlFlowNode for sys | Module sys |
107107
| 76 | ControlFlowNode for type | builtin-class type |
108108
| 76 | ControlFlowNode for type() | builtin-class module |
109+
| 77 | ControlFlowNode for unknown | ImportMember |
109110
| 78 | ControlFlowNode for type | builtin-class type |
110111
| 79 | ControlFlowNode for Dict | Dict |
111112
| 79 | ControlFlowNode for Tuple | Tuple |

0 commit comments

Comments
 (0)