Skip to content

Commit 6a1203a

Browse files
committed
Python: Adds modernized predicates
1 parent 6636f72 commit 6a1203a

File tree

1 file changed

+21
-0
lines changed

1 file changed

+21
-0
lines changed

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

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -269,6 +269,18 @@ class ExceptFlowNode extends ControlFlowNode {
269269
)
270270
}
271271

272+
private predicate handledObject(Value val, ClassValue cls, ControlFlowNode origin) {
273+
val.getClass() = cls and
274+
(
275+
this.getType().pointsTo(val, origin)
276+
or
277+
exists(TupleValue tup |
278+
this.handledObject(tup, ClassValue::tuple(), _) |
279+
val = tup.getItem(_) and origin.pointsTo(val)
280+
)
281+
)
282+
}
283+
272284
/** Gets the inferred type(s) that are handled by this node, splitting tuples if possible. */
273285
pragma [noinline]
274286
predicate handledException_objectapi(Object obj, ClassObject cls, ControlFlowNode origin) {
@@ -278,6 +290,15 @@ class ExceptFlowNode extends ControlFlowNode {
278290
origin = this
279291
}
280292

293+
/** Gets the inferred type(s) that are handled by this node, splitting tuples if possible. */
294+
pragma [noinline]
295+
predicate handledException(Value val, ClassValue cls, ControlFlowNode origin) {
296+
this.handledObject(val, cls, origin) and not cls = ClassValue::tuple()
297+
or
298+
not exists(this.getNode().(ExceptStmt).getType()) and val = ClassValue::baseException() and cls = ClassValue::type() and
299+
origin = this
300+
}
301+
281302
/** Whether this `except` handles `cls` */
282303
predicate handles(ClassObject cls) {
283304
exists(ClassObject handled |

0 commit comments

Comments
 (0)