Skip to content

Commit 74f0bdf

Browse files
authored
Python: Fix "unused disjunct" warnings
For the most part, these boil down to "some global property holds, and so this relation contains all instances of class `X`". The fix is to explicitly build the cartesian product (which we were already building implicitly anyway) by adding `and exists(var)` to the disjunct that did not mention `var`. Note that these cartesian products are always with singletons on one side, and so should be unproblematic.
1 parent b39f383 commit 74f0bdf

File tree

5 files changed

+6
-6
lines changed

5 files changed

+6
-6
lines changed

python/ql/lib/semmle/python/Module.qll

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -196,7 +196,7 @@ private predicate isPotentialSourcePackage(Folder f) {
196196
private predicate isPotentialPackage(Folder f) {
197197
exists(f.getFile("__init__.py"))
198198
or
199-
py_flags_versioned("options.respect_init", "False", _) and major_version() = 2
199+
py_flags_versioned("options.respect_init", "False", _) and major_version() = 2 and exists(f)
200200
}
201201

202202
private string moduleNameFromBase(Container file) {

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ deprecated class CallContext extends TaintTrackingContext {
1515
)
1616
)
1717
or
18-
this.isTop()
18+
this.isTop() and exists(s)
1919
}
2020
}
2121

python/ql/lib/semmle/python/pointsto/Base.qll

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,7 @@ int version_tuple_compare(Object t) {
124124
predicate baseless_is_new_style(ClassObject cls) {
125125
cls.isBuiltin()
126126
or
127-
major_version() = 3
127+
major_version() = 3 and exists(cls)
128128
or
129129
exists(cls.declaredMetaClass())
130130
}

python/ql/lib/semmle/python/pointsto/MRO.qll

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -329,7 +329,7 @@ private class ClassListList extends TClassListList {
329329
result = ConsList(removed_head, removed_tail)
330330
)
331331
or
332-
this = EmptyList() and result = EmptyList()
332+
this = EmptyList() and result = EmptyList() and exists(cls)
333333
}
334334

335335
pragma[nomagic]

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1076,7 +1076,7 @@ module InterProceduralPointsTo {
10761076
/** Helper for default_parameter_points_to */
10771077
pragma[noinline]
10781078
private predicate context_for_default_value(ParameterDefinition def, PointsToContext context) {
1079-
context.isRuntime()
1079+
context.isRuntime() and exists(def)
10801080
or
10811081
exists(PointsToContext caller, CallNode call, PythonFunctionObjectInternal func, int n |
10821082
context.fromCall(call, func, caller) and
@@ -2286,7 +2286,7 @@ module Types {
22862286
func != six_add_metaclass_function() and result = false
22872287
)
22882288
or
2289-
not exists(Module m | m.getName() = "six") and result = false
2289+
not exists(Module m | m.getName() = "six") and result = false and exists(cls)
22902290
or
22912291
exists(Class pycls |
22922292
pycls = cls.getScope() and

0 commit comments

Comments
 (0)