Skip to content

CodeQL to get python attribute and corresponding definition #12313

Answered by yoff
yuval-piiano asked this question in Q&A
Discussion options

You must be logged in to vote

Hi, using Value is considered old-fashion these days, I suggest you use the API graph instead.
You are facing two complications:

  1. AddressData is not an externally defined class, so we have to create a new entry point. The class AddressData below does this.
  2. The class is decorated, so we have to actually find the result of the decorator. The member predicate getDataclass does this.

Once this is done, any(AddressData ad).getDataclass().getReturn() will match ad = AddressData("my address") (because getReturn matches the act of instantiating the class) and we can go from there.

I have commented the code a bit, but feel free to ask further questions :-)

import python
import semmle.python.dataf…

Replies: 2 comments 3 replies

Comment options

You must be logged in to vote
0 replies
Answer selected by yuval-piiano
Comment options

You must be logged in to vote
3 replies
@yoff
Comment options

yoff Mar 1, 2023
Maintainer

@yuval-piiano
Comment options

@RasmusWL
Comment options

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
3 participants