-
Notifications
You must be signed in to change notification settings - Fork 22
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
Simple DefUse Analysis #28
Comments
You shouldn't take a line a approach, but a node approach:
hope it helps? |
Could I also ask here? I have a close task - I need to find all usages of definitions and return links between definition and uses on module level. Until now, I've built DefUseChains, traversed each chain, found all chain ends and then with ancestors linked each start and end of the chain to the first ancestor. It seems that the solution that you provided solves the same problem but much easier, however I've run both solutions on the same piece of code and got different amount of these links. Am I missing something and which approach will be better for this problem? Later today I will try to come up with a reproducible example. |
@TitovS : the snippet above only finds top-level definition, while yours would also find inner definition, maybe that's the reason? |
I suggest we close this issue. |
Hi, I have been trying to perform a simple DefUse analysis on my code. Essentially, I just want to know for a given line of code, which other lines of code should be executed before it.
code = open("my_code.py", "r").read()
module = ast.parse(code)
duc = beniget.DefUseChains()
duc.visit(module)
From the example in the code, I know the
duc
should contain the required information in theduc.chains
. But I am a little confused about the right way to access the information. For example, I know each line of code would be presented as a node inmodule
and I can access it by doingmodule.body[line #]
, how can I look it up in theduc.chains
? I have tried different ways and unfortunately no luck.The text was updated successfully, but these errors were encountered: