Skip to content

Commit f4a054e

Browse files
committed
apply range pattern patch to python
1 parent d2d6b2c commit f4a054e

File tree

5 files changed

+28
-48
lines changed

5 files changed

+28
-48
lines changed

python/ql/lib/semmle/python/dataflow/new/internal/DataFlowPrivate.qll

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1345,10 +1345,8 @@ module IterableUnpacking {
13451345
}
13461346

13471347
/** A (possibly recursive) target of an unpacking assignment which is also a sequence. */
1348-
class UnpackingAssignmentSequenceTarget extends UnpackingAssignmentTarget {
1349-
UnpackingAssignmentSequenceTarget() { this instanceof SequenceNode }
1350-
1351-
ControlFlowNode getElement(int i) { result = this.(SequenceNode).getElement(i) }
1348+
class UnpackingAssignmentSequenceTarget extends UnpackingAssignmentTarget instanceof SequenceNode {
1349+
ControlFlowNode getElement(int i) { result = super.getElement(i) }
13521350

13531351
ControlFlowNode getAnElement() { result = this.getElement(_) }
13541352
}

python/ql/lib/semmle/python/dataflow/old/TaintTracking.qll

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -639,16 +639,14 @@ module DataFlow {
639639
}
640640
}
641641

642-
deprecated private class ConfigurationAdapter extends TaintTracking::Configuration {
643-
ConfigurationAdapter() { this instanceof Configuration }
644-
642+
deprecated private class ConfigurationAdapter extends TaintTracking::Configuration instanceof Configuration {
645643
override predicate isSource(DataFlow::Node node, TaintKind kind) {
646-
this.(Configuration).isSource(node.asCfgNode()) and
644+
Configuration.super.isSource(node.asCfgNode()) and
647645
kind instanceof DataFlowType
648646
}
649647

650648
override predicate isSink(DataFlow::Node node, TaintKind kind) {
651-
this.(Configuration).isSink(node.asCfgNode()) and
649+
Configuration.super.isSink(node.asCfgNode()) and
652650
kind instanceof DataFlowType
653651
}
654652
}

python/ql/lib/semmle/python/dependencies/TechInventory.qll

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,16 +14,14 @@ string munge(File sourceFile, ExternalPackage package) {
1414
result = "/" + sourceFile.getRelativePath() + "<|>" + package.getName() + "<|>unknown"
1515
}
1616

17-
abstract class ExternalPackage extends Object {
18-
ExternalPackage() { this instanceof ModuleObject }
19-
17+
abstract class ExternalPackage extends Object instanceof ModuleObject {
2018
abstract string getName();
2119

2220
abstract string getVersion();
2321

24-
Object getAttribute(string name) { result = this.(ModuleObject).attr(name) }
22+
Object getAttribute(string name) { result = super.attr(name) }
2523

26-
PackageObject getPackage() { result = this.(ModuleObject).getPackage() }
24+
PackageObject getPackage() { result = super.getPackage() }
2725
}
2826

2927
bindingset[text]

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

Lines changed: 18 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -147,9 +147,7 @@ class Value extends TObject {
147147
* Class representing modules in the Python program
148148
* Each `ModuleValue` represents a module object in the Python program.
149149
*/
150-
class ModuleValue extends Value {
151-
ModuleValue() { this instanceof ModuleObjectInternal }
152-
150+
class ModuleValue extends Value instanceof ModuleObjectInternal {
153151
/**
154152
* Holds if this module "exports" name.
155153
* That is, does it define `name` in `__all__` or is
@@ -159,7 +157,7 @@ class ModuleValue extends Value {
159157
predicate exports(string name) { PointsTo::moduleExports(this, name) }
160158

161159
/** Gets the scope for this module, provided that it is a Python module. */
162-
ModuleScope getScope() { result = this.(ModuleObjectInternal).getSourceModule() }
160+
ModuleScope getScope() { result = super.getSourceModule() }
163161

164162
/**
165163
* Gets the container path for this module. Will be the file for a Python module,
@@ -181,7 +179,7 @@ class ModuleValue extends Value {
181179
predicate isPackage() { this instanceof PackageObjectInternal }
182180

183181
/** Whether the complete set of names "exported" by this module can be accurately determined */
184-
predicate hasCompleteExportInfo() { this.(ModuleObjectInternal).hasCompleteExportInfo() }
182+
predicate hasCompleteExportInfo() { super.hasCompleteExportInfo() }
185183

186184
/** Get a module that this module imports */
187185
ModuleValue getAnImportedModule() { result.importedAs(this.getScope().getAnImportedModuleName()) }
@@ -345,25 +343,21 @@ module Value {
345343
* Callables include Python functions, built-in functions and bound-methods,
346344
* but not classes.
347345
*/
348-
class CallableValue extends Value {
349-
CallableValue() { this instanceof CallableObjectInternal }
350-
346+
class CallableValue extends Value instanceof CallableObjectInternal {
351347
/**
352348
* Holds if this callable never returns once called.
353349
* For example, `sys.exit`
354350
*/
355-
predicate neverReturns() { this.(CallableObjectInternal).neverReturns() }
351+
predicate neverReturns() { super.neverReturns() }
356352

357353
/** Gets the scope for this function, provided that it is a Python function. */
358354
FunctionScope getScope() { result = this.(PythonFunctionObjectInternal).getScope() }
359355

360356
/** Gets the `n`th parameter node of this callable. */
361-
NameNode getParameter(int n) { result = this.(CallableObjectInternal).getParameter(n) }
357+
NameNode getParameter(int n) { result = super.getParameter(n) }
362358

363359
/** Gets the `name`d parameter node of this callable. */
364-
NameNode getParameterByName(string name) {
365-
result = this.(CallableObjectInternal).getParameterByName(name)
366-
}
360+
NameNode getParameterByName(string name) { result = super.getParameterByName(name) }
367361

368362
/**
369363
* Gets the argument in `call` corresponding to the `n`'th positional parameter of this callable.
@@ -452,23 +446,21 @@ class CallableValue extends Value {
452446
* Class representing bound-methods, such as `o.func`, where `o` is an instance
453447
* of a class that has a callable attribute `func`.
454448
*/
455-
class BoundMethodValue extends CallableValue {
456-
BoundMethodValue() { this instanceof BoundMethodObjectInternal }
457-
449+
class BoundMethodValue extends CallableValue instanceof BoundMethodObjectInternal {
458450
/**
459451
* Gets the callable that will be used when `this` is called.
460452
* The actual callable for `func` in `o.func`.
461453
*/
462-
CallableValue getFunction() { result = this.(BoundMethodObjectInternal).getFunction() }
454+
CallableValue getFunction() { result = super.getFunction() }
463455

464456
/**
465457
* Gets the value that will be used for the `self` parameter when `this` is called.
466458
* The value for `o` in `o.func`.
467459
*/
468-
Value getSelf() { result = this.(BoundMethodObjectInternal).getSelf() }
460+
Value getSelf() { result = super.getSelf() }
469461

470462
/** Gets the parameter node that will be used for `self`. */
471-
NameNode getSelfParameter() { result = this.(BoundMethodObjectInternal).getSelfParameter() }
463+
NameNode getSelfParameter() { result = super.getSelfParameter() }
472464
}
473465

474466
/**
@@ -831,12 +823,10 @@ class BuiltinMethodValue extends FunctionValue {
831823
/**
832824
* A class representing sequence objects with a length and tracked items.
833825
*/
834-
class SequenceValue extends Value {
835-
SequenceValue() { this instanceof SequenceObjectInternal }
836-
837-
Value getItem(int n) { result = this.(SequenceObjectInternal).getItem(n) }
826+
class SequenceValue extends Value instanceof SequenceObjectInternal {
827+
Value getItem(int n) { result = super.getItem(n) }
838828

839-
int length() { result = this.(SequenceObjectInternal).length() }
829+
int length() { result = super.length() }
840830
}
841831

842832
/** A class representing tuple objects */
@@ -887,14 +877,12 @@ class NumericValue extends Value {
887877
* https://docs.python.org/3/howto/descriptor.html#properties
888878
* https://docs.python.org/3/library/functions.html#property
889879
*/
890-
class PropertyValue extends Value {
891-
PropertyValue() { this instanceof PropertyInternal }
892-
893-
CallableValue getGetter() { result = this.(PropertyInternal).getGetter() }
880+
class PropertyValue extends Value instanceof PropertyInternal {
881+
CallableValue getGetter() { result = super.getGetter() }
894882

895-
CallableValue getSetter() { result = this.(PropertyInternal).getSetter() }
883+
CallableValue getSetter() { result = super.getSetter() }
896884

897-
CallableValue getDeleter() { result = this.(PropertyInternal).getDeleter() }
885+
CallableValue getDeleter() { result = super.getDeleter() }
898886
}
899887

900888
/** A method-resolution-order sequence of classes */

python/ql/lib/semmle/python/types/Extensions.qll

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -151,12 +151,10 @@ class ReModulePointToExtension extends PointsToExtension {
151151
private predicate pointsTo_helper(Context context) { context.appliesTo(this) }
152152
}
153153

154-
deprecated private class BackwardCompatiblePointToExtension extends PointsToExtension {
155-
BackwardCompatiblePointToExtension() { this instanceof CustomPointsToFact }
156-
154+
deprecated private class BackwardCompatiblePointToExtension extends PointsToExtension instanceof CustomPointsToFact {
157155
override predicate pointsTo(Context context, ObjectInternal value, ControlFlowNode origin) {
158156
exists(Object obj, ClassObject cls |
159-
this.(CustomPointsToFact).pointsTo(context, obj, cls, origin)
157+
CustomPointsToFact.super.pointsTo(context, obj, cls, origin)
160158
|
161159
value.getBuiltin() = obj
162160
or

0 commit comments

Comments
 (0)