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

Add module frame to catch raises in top-level code. #2

Closed dbieber closed 2 years ago

dbieber commented 2 years ago

Add module frame to catch raises in top-level code. Also marks except expressions and finally blocks as branch points.

An "except A:"'s branch decision is whether the current exception matches A. At the end of a finally block, the branch decision is whether an exception is currently being raised.

This includes https://github.com/google-research/python-graphs/pull/3: Splits "branches" into branches, except_branches, and reraise_branches.

branches are your usual branch decisions: ifs, fors, and whiles. except_branches are at "except E:" statements, with True indicating the exception matches and False indicating it does not reraise_branches are at the end of "finally:" blocks, with True indicating the path taken after finally if an error has been raised previously, and False indicating the path taken if there's nothing to reraise at the end of the finally.