New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Python: support grouped exceptions #11244
base: main
Are you sure you want to change the base?
Conversation
also widen type of `Try::getHandler` to `Stmt`. `ExceptStmt` is now too narrow, as a handler can also be of type `ExceptGroupStmt`.
- wrap `getType` and `getName`, considering dominance - do not implement all the handles predicates
also add to ordinary `except`
| | 23 = @py_With | ||
| | 24 = @py_TemplateWrite | ||
| | 25 = @py_AnnAssign; | ||
| | 7 = @py_ExceptGroupStmt |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm wondering if it would have been easier for update/downgrade scripts if this new kind was added in the end (as id=26)? (too late now, but something to consider for the future)
python/downgrades/47e552c4357a04c5735355fad818630daee4a5ac/py_stmts.ql
Outdated
Show resolved
Hide resolved
| # This should cover all the syntactical constructs that we hope to support. | ||
| # Headings refer to https://docs.python.org/3/reference/expressions.html, | ||
| # and are selected whenever they incur dataflow. | ||
| # Intended sources should be the variable `SOURCE` and intended sinks should be | ||
| # arguments to the function `SINK` (see python/ql/test/experimental/dataflow/testConfig.qll). | ||
| # | ||
| # Functions whose name ends with "_with_local_flow" will also be tested for local flow. | ||
| # | ||
| # All functions starting with "test_" should run and execute `print("OK")` exactly once. | ||
| # This can be checked by running validTest.py. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Some of this text is not valid, and should be removed. I would probably delete all of it, but I think it's also acceptable to have the last two lines... up to you
| @@ -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() | |||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The fact that you had to do these rewrites makes me wonder if other end-users are going to be affected in the same way, without the knowledge that they need to re-write their code? (at least this needs to be called out in the change note)
Overall I totally understand why you ended up doing it this way, and would probably have done the same if I were in your position... it just begs for us to support automatic rewrites based on qlpack versions
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, it does seem the only reasonable way to do it, but it still annoys me that we get a user facing breakage here..
| override Stmt getHandler(int i) { result = Try_.super.getHandler(i) } | ||
|
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
QL4QL suggests that you can also remove this override.
| override Stmt getHandler(int i) { result = Try_.super.getHandler(i) } |
python/ql/lib/change-notes/2022-11-14-grouped-exceptions-breaking.md
Outdated
Show resolved
Hide resolved
Co-authored-by: Rasmus Wriedt Larsen <rasmuswl@github.com>
| @@ -364,10 +386,13 @@ | |||
| result = this.getAnOrelse() | |||
| } | |||
|
|
|||
| override ExceptStmt getHandler(int i) { result = Try_.super.getHandler(i) } | |||
| override Stmt getHandler(int i) { result = Try_.super.getHandler(i) } | |||
Check warning
Code scanning / CodeQL
Redundant override Warning
ql part of github/semmle-code#44008