-
Notifications
You must be signed in to change notification settings - Fork 1.7k
Python: Support type annotations in call graph #19672
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 type annotations in call graph #19672
Conversation
Adds support for tracking instances via type annotations. Also adds a convenience method to the newly added `Annotation` class, `getAnnotatedExpression`, that returns the expression that is annotated with the given type. For return annotations this is any value returned from the annotated function in question. Co-authored-by: Napalys Klicius <napalys@github.com>
Co-authored-by: Napalys Klicius <napalys@github.com>
Also fixes an issue with the return type annotations that caused these to not work properly. Currently, annotated assignments don't work properly, due to the fact that our flow relation doesn't consider flow going to the "type" part of an annotated assignment. This means that in `x : Foo`, we do correctly note that `x` is annotated with `Foo`, but we have no idea what `Foo` is, since it has no incoming flow. To fix this we should probably just extend the flow relation, but this may need to be done with some care, so I have left it as future work.
cf8c8bc
to
c6c6a85
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.
Pull Request Overview
This PR adds support for type annotations in the call graph tracking system, enabling better analysis of method calls on annotated variables. The implementation allows the call graph to recognize that variables with type annotations (like x: Foo
) may be instances of the annotated type, improving static analysis accuracy.
Key changes:
- Enhanced call graph to track instances through type annotations
- Added
getAnnotatedExpression()
method to theAnnotation
class for retrieving annotated expressions - Extended instance tracking to include parameter, return, and variable type annotations
Reviewed Changes
Copilot reviewed 6 out of 6 changed files in this pull request and generated 1 comment.
Show a summary per file
File | Description |
---|---|
type_annotations.py | Test cases demonstrating type annotation tracking for parameters, returns, and variables |
InlineCallGraphTest.qlref | Reference file for running call graph tests |
DataFlowDispatch.qll | Core implementation adding annotation-based instance tracking to the call graph |
Exprs.qll | New getAnnotatedExpression() method in the Annotation class |
2025-06-04-call-graph-type-annotations.md | Release notes documenting the new feature |
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.
Thank you, looks good to me
DCA looks uneventful. I'll go ahead with the merge. |
Adds support for tracking instances via type annotations. Also adds a convenience method to the newly added
Annotation
class,getAnnotatedExpression
, that returns the expression that is annotated with the given type. For return annotations this is any value returned from the annotated function in question.