-
Notifications
You must be signed in to change notification settings - Fork 1.7k
Python: Modernize the init-calls-subclass query #19709
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 init-calls-subclass query #19709
Conversation
QHelp previews: python/ql/src/Classes/InitCallsSubclass/InitCallsSubclassMethod.qhelp
|
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 py/init-calls-subclass
QL query by replacing the old implementation with a new dataflow-based approach.
- Removes the legacy
InitCallsSubclassMethod.ql
. - Adds a new directory and file under
InitCallsSubclass/
usingDataFlow
predicates. - Defines two predicates (
initSelfCall
andinitSelfCallOverridden
) to detect subclass-overridden calls in__init__
.
Reviewed Changes
Copilot reviewed 4 out of 4 changed files in this pull request and generated 1 comment.
File | Description |
---|---|
python/ql/src/Classes/InitCallsSubclassMethod.ql | Deleted the legacy query file |
python/ql/src/Classes/InitCallsSubclass/InitCallsSubclassMethod.ql | Added modernized dataflow-based query implementation |
Comments suppressed due to low confidence (4)
python/ql/src/Classes/InitCallsSubclass/InitCallsSubclassMethod.ql:28
- [nitpick] The parameter name
override
is ambiguous and matches a language keyword. Consider renaming it to something likeoverridingMethod
for clarity.
predicate initSelfCallOverridden(Function init, DataFlow::MethodCallNode call, Function override) {
python/ql/src/Classes/InitCallsSubclass/InitCallsSubclassMethod.ql:18
- [nitpick] It would be helpful to add a brief doc comment above this predicate explaining its purpose and parameters for future maintainers.
predicate initSelfCall(Function init, DataFlow::MethodCallNode call) {
python/ql/src/Classes/InitCallsSubclass/InitCallsSubclassMethod.ql:38
- The new dataflow-based implementation should be accompanied by tests to validate that overridden
__init__
calls are correctly detected; consider adding or updating QL tests.
from Function init, DataFlow::MethodCallNode call, Function override
python/ql/src/Classes/InitCallsSubclass/InitCallsSubclassMethod.ql:16
- This import isn't used in the new query. Consider removing it to keep dependencies minimal.
import semmle.python.dataflow.new.internal.DataFlowDispatch
python/ql/src/Classes/InitCallsSubclass/InitCallsSubclassMethod.ql
Outdated
Show resolved
Hide resolved
0f7a24e
to
2aad607
Compare
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.
A few comments/suggestions, but otherwise this looks good to me.
(Feel free to postpone my suggestion about self
parameters to a later PR if you just want to merge the present one.)
Also, in future PRs could you make sure that you don't rename/move and also modify files in the same commit? This really confuses the diff (as it doesn't know the two files should be linked up) and makes it difficult to see what the actual differences are.
python/ql/src/Classes/InitCallsSubclass/InitCallsSubclassMethod.qhelp
Outdated
Show resolved
Hide resolved
python/ql/test/query-tests/Classes/init-calls-subclass-method/init_calls_subclass.py
Outdated
Show resolved
Hide resolved
python/ql/test/query-tests/Classes/init-calls-subclass-method/init_calls_subclass.py
Outdated
Show resolved
Hide resolved
…f, or the call is last in the initialisation.
…be a problem if the subclass overrides initialisation.
89f0843
to
d1bd722
Compare
No description provided.