(Python) Resolve FQNs for definitions

Assuming we have a set of definitions captured by ast-grep, the next step is to compute a fully qualified name (FQN) for each one.

For example, if our input file is utils/math_ops.py:

class A:
    def foo(self):
        pass

    class B:
        def bar(self):
            pass

def fizz():
    pass

We want to record:

  • utils.math_ops.A
  • utils.math_ops.A.foo
  • utils.math_ops.A.B
  • utils.math_ops.A.B.bar
  • utils.math_ops.fizz

This will involve traversing the AST and building a stack of "scope names" to track nested contexts (e.g. module -> class -> function).

Edited by Jonathan Shobrook