python: convenience methods for handler types

This commit is contained in:
Rasmus Lerchedahl Petersen
2022-11-10 14:47:02 +01:00
parent e67515fae7
commit 7d05ba38d5
2 changed files with 7 additions and 1 deletions

View File

@@ -392,6 +392,12 @@ class Try extends Try_ {
/** Gets an exception handler of this try statement. */
override Stmt getAHandler() { result = Try_.super.getAHandler() }
/** Gets a normal exception handler, `except`, of this try statement. */
ExceptStmt getANormalHandler() { result = this.getAHandler() }
/** Gets a group exception handler, `except*`, of this try statement. */
ExceptGroupStmt getAGroupHandler() { result = this.getAHandler() }
override Stmt getLastStatement() {
result = this.getFinalbody().getLastItem().getLastStatement()
or

View File

@@ -52,7 +52,7 @@ predicate iter_not_exhausted(EssaVariable iterator) {
predicate stop_iteration_handled(CallNode call) {
exists(Try t |
t.containsInScope(call.getNode()) and
t.getAHandler().getType() = stopIteration().getAValueReachableFromSource().asExpr()
t.getANormalHandler().getType() = stopIteration().getAValueReachableFromSource().asExpr()
)
}