-
Notifications
You must be signed in to change notification settings - Fork 1.9k
Python: Modernize the Unreachable Except Block query #20263
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: Modernize the Unreachable Except Block query #20263
Conversation
However, we lose some results due to not considering builtin/stdlib types.
|
QHelp previews: python/ql/src/Exceptions/IncorrectExceptOrder.qhelpUnreachable
|
|
Due to a strange dataflow issue, non-builtin classes do not seem to be tracked to the type of an Except block. |
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.
Pull Request Overview
This PR modernizes the "Unreachable Except Block" query by replacing the outdated pointsTo mechanism with newer dataflow tracking and implementing comprehensive modeling for builtin exception type subclass relations.
- Replaced
pointsTowith modern dataflow tracking and API graphs - Added comprehensive builtin exception hierarchy modeling through a generated YAML file
- Enhanced the query to handle both user-defined and builtin exception types with proper subclass tracking
Reviewed Changes
Copilot reviewed 11 out of 11 changed files in this pull request and generated no comments.
Show a summary per file
| File | Description |
|---|---|
| python/ql/src/Exceptions/IncorrectExceptOrder.ql | Main query rewrite using new dataflow approach and ExceptType abstraction |
| python/ql/src/Exceptions/IncorrectExceptOrder.qhelp | Minor documentation updates and Python 3 reference links |
| python/ql/src/meta/ClassHierarchy/process-builtin-exceptions.py | New script to generate builtin exception hierarchy data |
| python/ql/lib/semmle/python/frameworks/builtins.model.yml | Generated YAML file containing builtin exception subclass relationships |
| python/ql/test/query-tests/Exceptions/general/*.expected | Updated test expectations reflecting new query behavior |
| python/ql/test/query-tests/Exceptions/general/exceptions_test.py | Added test cases for custom exception hierarchies |
| python/ql/test/query-tests/Exceptions/general/IncorrectExceptOrder.qlref | Updated test configuration to use inline expectations |
Comments suppressed due to low confidence (3)
python/ql/src/Exceptions/IncorrectExceptOrder.ql:1
- Inconsistent spacing: line 68 has no trailing space while line 69 has a trailing space after 'pass'.
/**
python/ql/src/Exceptions/IncorrectExceptOrder.ql:1
- Inconsistent spacing: both lines 78 and 82 have trailing spaces after 'pass' which should be removed for consistency.
/**
python/ql/src/Exceptions/IncorrectExceptOrder.ql:1
- Inconsistent spacing: both lines 78 and 82 have trailing spaces after 'pass' which should be removed for consistency.
/**
tausbn
left a comment
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.
One suggestion, otherwise this looks good to me. The missing flow is annoying, but I don't see a quick fix (other than digging into the data-flow library and adding this flow).
| TClass(Class c) or | ||
| TBuiltin(string name) { builtinException(name) } | ||
|
|
||
| class ExceptType extends TExceptType { |
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 many uses of <class-stuff> or <builtin-stuff> in the various member predicates suggests that it might be better to create two separate subclasses of ExceptType that each override the (abstract) predicates on this type in a different way.
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.
Perhaps, though that approach may be a bit longer.
Replaces use of
pointsTo.Implements modelling for subclass relations of builtin exception types.