Skip to content

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

Merged
merged 3 commits into from
Jul 11, 2025

Conversation

tausbn
Copy link
Contributor

@tausbn tausbn commented Jun 4, 2025

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.

tausbn and others added 3 commits July 11, 2025 12:03
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.
@tausbn tausbn force-pushed the tausbn/python-support-type-annotations-in-call-graph branch from cf8c8bc to c6c6a85 Compare July 11, 2025 12:03
@tausbn tausbn marked this pull request as ready for review July 11, 2025 12:14
@Copilot Copilot AI review requested due to automatic review settings July 11, 2025 12:14
@tausbn tausbn requested a review from a team as a code owner July 11, 2025 12:14
Copy link
Contributor

@Copilot Copilot AI left a 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 the Annotation 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

Copy link
Contributor

@Napalys Napalys left a 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 :shipit: :fishsticks:

@tausbn
Copy link
Contributor Author

tausbn commented Jul 11, 2025

DCA looks uneventful. I'll go ahead with the merge.

@tausbn tausbn merged commit 344535b into main Jul 11, 2025
17 checks passed
@tausbn tausbn deleted the tausbn/python-support-type-annotations-in-call-graph branch July 11, 2025 14:44
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy