Skip to content

Commit 9044ff6

Browse files
committed
Python: Autoformat rest of semmle/python.
1 parent 810e91e commit 9044ff6

17 files changed

Lines changed: 759 additions & 1048 deletions

File tree

python/ql/src/semmle/python/dataflow/Implementation.qll

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -57,8 +57,8 @@ private newtype TAttributePath =
5757
* It might make sense to add another level, attribute of attribute.
5858
* But some experimentation would be needed.
5959
*/
60-
TAttribute(string name) { exists(Attribute a | a.getName() = name) }
6160

61+
TAttribute(string name) { exists(Attribute a | a.getName() = name) }
6262

6363
/**
6464
* The attribute of the tracked value holding the taint.
@@ -445,9 +445,8 @@ class TaintTrackingImplementation extends string {
445445
context = TNoParam() and
446446
src = TTaintTrackingNode_(retval, TNoParam(), path, kind, this) and
447447
node.asCfgNode() = call and
448-
retval.asCfgNode() = any(Return ret | ret.getScope() = pyfunc.getScope())
449-
.getValue()
450-
.getAFlowNode()
448+
retval.asCfgNode() =
449+
any(Return ret | ret.getScope() = pyfunc.getScope()).getValue().getAFlowNode()
451450
) and
452451
edgeLabel = "return"
453452
}
@@ -469,9 +468,8 @@ class TaintTrackingImplementation extends string {
469468
this.callContexts(call, src, pyfunc, context, callee) and
470469
retnode = TTaintTrackingNode_(retval, callee, path, kind, this) and
471470
node.asCfgNode() = call and
472-
retval.asCfgNode() = any(Return ret | ret.getScope() = pyfunc.getScope())
473-
.getValue()
474-
.getAFlowNode()
471+
retval.asCfgNode() =
472+
any(Return ret | ret.getScope() = pyfunc.getScope()).getValue().getAFlowNode()
475473
) and
476474
edgeLabel = "call"
477475
}
@@ -717,7 +715,8 @@ private class EssaTaintTracking extends string {
717715
path.noAttribute()
718716
|
719717
assign.getValue().getAFlowNode() = srcnode.asCfgNode() and
720-
kind = iterable_unpacking_descent(assign.getATarget().getAFlowNode(), defn.getDefiningNode(),
718+
kind =
719+
iterable_unpacking_descent(assign.getATarget().getAFlowNode(), defn.getDefiningNode(),
721720
srckind)
722721
)
723722
}
@@ -734,8 +733,8 @@ private class EssaTaintTracking extends string {
734733
then result = parent_kind
735734
else result = parent_kind.getMember()
736735
or
737-
result = iterable_unpacking_descent(left_parent.getAnElement(), left_defn,
738-
parent_kind.getMember())
736+
result =
737+
iterable_unpacking_descent(left_parent.getAnElement(), left_defn, parent_kind.getMember())
739738
}
740739

741740
pragma[noinline]

python/ql/src/semmle/python/dependencies/Dependencies.qll

Lines changed: 26 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,14 @@
1-
21
import python
32
import semmle.python.dependencies.DependencyKind
43

54
private predicate importDependency(Object target, AstNode source) {
6-
source.getScope() != target.getOrigin() and /* Imports of own module are ignored */
5+
source.getScope() != target.getOrigin() and
6+
/* Imports of own module are ignored */
77
(
88
exists(ModuleObject importee, ImportingStmt imp_stmt |
99
source = imp_stmt and
10-
importee = target |
10+
importee = target
11+
|
1112
exists(ImportMember im | imp_stmt.contains(im) |
1213
importee.importedAs(im.getImportedModuleName())
1314
)
@@ -23,28 +24,22 @@ private predicate importDependency(Object target, AstNode source) {
2324
)
2425
or
2526
/* from m import name, where m.name is not a submodule */
26-
exists(PythonModuleObject importee, ImportingStmt imp_stmt |
27-
source = imp_stmt |
27+
exists(PythonModuleObject importee, ImportingStmt imp_stmt | source = imp_stmt |
2828
exists(ImportMember im | imp_stmt.contains(im) |
29-
importee.importedAs(im.getModule().(ImportExpr).getImportedModuleName())
30-
and
29+
importee.importedAs(im.getModule().(ImportExpr).getImportedModuleName()) and
3130
defn_of_module_attribute(target, importee.getModule(), im.getName())
3231
)
3332
)
3433
)
3534
}
3635

3736
class PythonImport extends DependencyKind {
38-
39-
PythonImport() {
40-
this = "import"
41-
}
37+
PythonImport() { this = "import" }
4238

4339
override predicate isADependency(AstNode source, Object target) {
4440
this = this and
4541
importDependency(target, source)
4642
}
47-
4843
}
4944

5045
private predicate interesting(Object target) {
@@ -58,10 +53,7 @@ private predicate interesting(Object target) {
5853
}
5954

6055
class PythonUse extends DependencyKind {
61-
62-
PythonUse() {
63-
this = "use"
64-
}
56+
PythonUse() { this = "use" }
6557

6658
override predicate isADependency(AstNode source, Object target) {
6759
interesting(target) and
@@ -71,58 +63,46 @@ class PythonUse extends DependencyKind {
7163
use.getNode() = source and
7264
use.refersTo(obj) and
7365
use.isLoad()
74-
|
66+
|
7567
interesting(obj) and target = obj
76-
)
77-
and
68+
) and
7869
not has_more_specific_dependency_source(source)
7970
}
80-
8171
}
8272

83-
/** Whether there is a more specific dependency source than this one.
73+
/**
74+
* Whether there is a more specific dependency source than this one.
8475
* E.g. if the expression pack.mod.func is a dependency on the function 'func' in 'pack.mod'
8576
* don't make pack.mod depend on the module 'pack.mod'
8677
*/
8778
private predicate has_more_specific_dependency_source(Expr e) {
88-
exists(Attribute member |
89-
member.getObject() = e |
79+
exists(Attribute member | member.getObject() = e |
9080
attribute_access_dependency(_, member)
9181
or
9282
has_more_specific_dependency_source(member)
9383
)
9484
}
9585

9686
class PythonInheritance extends DependencyKind {
97-
98-
PythonInheritance() {
99-
this = "inheritance"
100-
}
87+
PythonInheritance() { this = "inheritance" }
10188

10289
override predicate isADependency(AstNode source, Object target) {
10390
this = this and
104-
exists(ClassObject cls |
105-
source = cls.getOrigin()
106-
|
91+
exists(ClassObject cls | source = cls.getOrigin() |
10792
target = cls.getASuperType()
10893
or
10994
target = cls.getAnInferredType()
11095
)
11196
}
112-
11397
}
11498

11599
class PythonAttribute extends DependencyKind {
116-
117-
PythonAttribute() {
118-
this = "attribute"
119-
}
100+
PythonAttribute() { this = "attribute" }
120101

121102
override predicate isADependency(AstNode source, Object target) {
122103
this = this and
123104
attribute_access_dependency(target, source)
124105
}
125-
126106
}
127107

128108
private predicate attribute_access_dependency(Object target, AstNode source) {
@@ -133,30 +113,23 @@ private predicate attribute_access_dependency(Object target, AstNode source) {
133113
}
134114

135115
private predicate use_of_attribute(Attribute attr, Scope s, string name) {
136-
exists(AttrNode cfg |
137-
cfg.isLoad() and cfg.getNode() = attr
138-
|
139-
exists(Object obj |
140-
cfg.getObject(name).refersTo(obj) |
116+
exists(AttrNode cfg | cfg.isLoad() and cfg.getNode() = attr |
117+
exists(Object obj | cfg.getObject(name).refersTo(obj) |
141118
s = obj.(PythonModuleObject).getModule() or
142119
s = obj.(ClassObject).getPyClass()
143-
) or
144-
exists(ClassObject cls |
145-
cfg.getObject(name).refersTo(_, cls, _) |
146-
s = cls.getPyClass()
147120
)
121+
or
122+
exists(ClassObject cls | cfg.getObject(name).refersTo(_, cls, _) | s = cls.getPyClass())
148123
)
149124
or
150-
exists(SelfAttributeRead sar |
151-
sar = attr |
125+
exists(SelfAttributeRead sar | sar = attr |
152126
sar.getClass() = s and
153127
sar.getName() = name
154128
)
155129
}
156130

157131
private predicate defn_of_attribute(Object target, Scope s, string name) {
158-
exists(Assign asgn |
159-
target.(ControlFlowNode).getNode() = asgn |
132+
exists(Assign asgn | target.(ControlFlowNode).getNode() = asgn |
160133
defn_of_instance_attribute(asgn, s, name)
161134
or
162135
defn_of_class_attribute(asgn, s, name)
@@ -165,13 +138,14 @@ private predicate defn_of_attribute(Object target, Scope s, string name) {
165138
defn_of_module_attribute(target, s, name)
166139
}
167140

168-
/* Whether asgn defines an instance attribute, that is does
141+
/*
142+
* Whether asgn defines an instance attribute, that is does
169143
* asgn take the form self.name = ... where self is an instance
170144
* of class c and asgn is not a redefinition.
171145
*/
146+
172147
private predicate defn_of_instance_attribute(Assign asgn, Class c, string name) {
173-
exists(SelfAttributeStore sas |
174-
asgn.getATarget() = sas |
148+
exists(SelfAttributeStore sas | asgn.getATarget() = sas |
175149
sas.getClass() = c and
176150
sas.getName() = name and
177151
not exists(SelfAttributeStore in_init |

python/ql/src/semmle/python/dependencies/DependencyKind.qll

Lines changed: 8 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ import semmle.python.dependencies.Dependencies
33
/**
44
* A library describing an abstract mechanism for representing dependency categories.
55
*/
6-
76
/*
87
* A DependencyCategory is a unique string key used by Architect to identify different categories
98
* of dependencies that might be viewed independently.
@@ -12,20 +11,17 @@ import semmle.python.dependencies.Dependencies
1211
* accepted by Architect.
1312
* </p>
1413
*/
15-
abstract class DependencyKind extends string {
1614

15+
abstract class DependencyKind extends string {
1716
bindingset[this]
18-
DependencyKind() {
19-
this = this
20-
}
17+
DependencyKind() { this = this }
2118

2219
/* Tech inventory interface */
2320
/**
24-
* Identify dependencies associated with this category.
25-
* <p>
26-
* The source element is the source of the dependency.
27-
* </p>
28-
*/
21+
* Identify dependencies associated with this category.
22+
* <p>
23+
* The source element is the source of the dependency.
24+
* </p>
25+
*/
2926
abstract predicate isADependency(AstNode source, Object target);
30-
31-
}
27+
}

0 commit comments

Comments
 (0)