diff --git a/python/downgrades/47e552c4357a04c5735355fad818630daee4a5ac/py_stmts.ql b/python/downgrades/47e552c4357a04c5735355fad818630daee4a5ac/py_stmts.ql index 57f1dfdc1ec..667a1d5345c 100644 --- a/python/downgrades/47e552c4357a04c5735355fad818630daee4a5ac/py_stmts.ql +++ b/python/downgrades/47e552c4357a04c5735355fad818630daee4a5ac/py_stmts.ql @@ -14,6 +14,7 @@ class StmtList_ extends @py_stmt_list { */ bindingset[new_index] int old_index(int new_index) { + not new_index = 7 and if new_index < 7 then result = new_index else result + (8 - 7) = new_index } diff --git a/python/ql/lib/change-notes/2022-11-14-grouped-exceptions-breaking.md b/python/ql/lib/change-notes/2022-11-14-grouped-exceptions-breaking.md index 0eb63639d69..06bca7fe433 100644 --- a/python/ql/lib/change-notes/2022-11-14-grouped-exceptions-breaking.md +++ b/python/ql/lib/change-notes/2022-11-14-grouped-exceptions-breaking.md @@ -1,4 +1,4 @@ --- category: breaking --- -* `Try::getAHandler` no longer returns an `ExceptStmt`, as handlers may also be `ExceptGroupStmt`s. Instead, it returns a plain `Stmt`. This means that code of the form `try.getAHandler().getType()` will no longer work. Instead, use `try.getANormalHandler().getType()` or `try.getAGroupHandler().getType()`, depending on your use case. +* `Try.getAHandler()` and `Try.getHandler()` have results of type `Stmt` instead of `ExceptStmt`, as handlers may also be `ExceptGroupStmt`s (After Python 3.11 introduced PEP 654). This means that code of the form `try.getAHandler().getType()` will no longer work. Instead, use `try.getANormalHandler().getType()` or `try.getAGroupHandler().getType()`, depending on your use case. diff --git a/python/ql/lib/semmle/python/Stmts.qll b/python/ql/lib/semmle/python/Stmts.qll index fd2f7228362..07fa7f02a76 100644 --- a/python/ql/lib/semmle/python/Stmts.qll +++ b/python/ql/lib/semmle/python/Stmts.qll @@ -145,7 +145,6 @@ class Exec extends Exec_ { /** An except group statement (part of a `try` statement), such as `except* IOError as err:` */ class ExceptGroupStmt extends ExceptGroupStmt_ { - /* syntax: except Expr [ as Expr ]: */ /** Gets the immediately enclosing try statement */ Try getTry() { result.getAHandler() = this } diff --git a/python/ql/lib/semmle/python/essa/Essa.qll b/python/ql/lib/semmle/python/essa/Essa.qll index 272284cdf84..64b076d07c0 100644 --- a/python/ql/lib/semmle/python/essa/Essa.qll +++ b/python/ql/lib/semmle/python/essa/Essa.qll @@ -522,7 +522,7 @@ class ExceptionCapture extends EssaNodeDefinition { * `ExceptionType` in `except ExceptionType as ex:`. */ ControlFlowNode getType() { - exists(ExceptGroupFlowNode ex | + exists(ExceptFlowNode ex | ex.getName() = this.getDefiningNode() and result = ex.getType() ) diff --git a/python/ql/lib/semmle/python/types/Exceptions.qll b/python/ql/lib/semmle/python/types/Exceptions.qll index 635e7c459ae..93bace1cf51 100644 --- a/python/ql/lib/semmle/python/types/Exceptions.qll +++ b/python/ql/lib/semmle/python/types/Exceptions.qll @@ -453,7 +453,7 @@ class ExceptGroupFlowNode extends ControlFlowNode { /** * Gets the type handled by this exception handler. - * `eg` in `except* eg as e:` + * `ExceptionType` in `except* ExceptionType as e:` */ ControlFlowNode getType() { this.getBasicBlock().dominates(result.getBasicBlock()) and @@ -462,7 +462,7 @@ class ExceptGroupFlowNode extends ControlFlowNode { /** * Gets the name assigned to the handled exception, if any. - * `e` in `except* eg as e:` + * `e` in `except* ExceptionType as e:` */ ControlFlowNode getName() { this.getBasicBlock().dominates(result.getBasicBlock()) and