Skip to content

Commit 7d05ba3

Browse files
committed
python: convenience methods for handler types
1 parent e67515f commit 7d05ba3

File tree

2 files changed

+7
-1
lines changed

2 files changed

+7
-1
lines changed

python/ql/lib/semmle/python/Stmts.qll

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -392,6 +392,12 @@ class Try extends Try_ {
392392
/** Gets an exception handler of this try statement. */
393393
override Stmt getAHandler() { result = Try_.super.getAHandler() }
394394

395+
/** Gets a normal exception handler, `except`, of this try statement. */
396+
ExceptStmt getANormalHandler() { result = this.getAHandler() }
397+
398+
/** Gets a group exception handler, `except*`, of this try statement. */
399+
ExceptGroupStmt getAGroupHandler() { result = this.getAHandler() }
400+
395401
override Stmt getLastStatement() {
396402
result = this.getFinalbody().getLastItem().getLastStatement()
397403
or

python/ql/src/Exceptions/UnguardedNextInGenerator.ql

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ predicate iter_not_exhausted(EssaVariable iterator) {
5252
predicate stop_iteration_handled(CallNode call) {
5353
exists(Try t |
5454
t.containsInScope(call.getNode()) and
55-
t.getAHandler().getType() = stopIteration().getAValueReachableFromSource().asExpr()
55+
t.getANormalHandler().getType() = stopIteration().getAValueReachableFromSource().asExpr()
5656
)
5757
}
5858

0 commit comments

Comments
 (0)