Skip to content

Live Variables Analysis#2

Merged
AlexDimakos merged 6 commits into
AlexDimakos:mainfrom
Apanatshka:main
Apr 10, 2026
Merged

Live Variables Analysis#2
AlexDimakos merged 6 commits into
AlexDimakos:mainfrom
Apanatshka:main

Conversation

@Apanatshka

Copy link
Copy Markdown
Contributor

Have a look at tests/test_live_variables.py, especially the last test, to see how you might use it. Basically you can get a tuple of the live variables before and after the effect of a CSTNode using get_metadata, but only if the control-flow graph construction code has a line like:

prev = self._make_cfg_node(statement, instance, prev) # AugAssign

So the line above makes sure that cst.AugAssign statements are in the control-flow graph as a nodes, which means that the live variables analysis attaches the before/after info to it.

You can of course add more nodes to the control-flow graph if you like. I've specifically added a node for cst.Call so you can easily get live variables info at calls on entities.

@AlexDimakos AlexDimakos merged commit 25bc23b into AlexDimakos:main Apr 10, 2026
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants