google-research / python-graphs

A static analysis library for computing graph representations of Python programs suitable for use with graph neural networks.
Apache License 2.0
325 stars 39 forks source link

Control Flow is incorrectly produced for code containing "with" statement #17

Open datapaf opened 1 year ago

datapaf commented 1 year ago

Hello! Trying to produce control flow graph for the following code:

def get_fun(fun):
    with _get_serv(ret=None, commit=True) as cur:
        sql = 'SELECT s.id, s.jid, s.full_ret FROM salt_returns s JOIN (SELECT MAX(`jid`) as jid from salt_returns GROUP BY fun, id) max ON s.jid = max.jid WHERE s.fun = %s'
        cur.execute(sql, (fun,))
        data = cur.fetchall()
        ret = {}
        if data:
            for (minion, _, full_ret) in data:
                ret[minion] = full_ret
        return ret

I get the following graph: cfg (1)

I believe this graph does not represent the actual control flow of the code