Skip to content

Instantly share code, notes, and snippets.

@PiotrZakrzewski
Last active April 5, 2021 07:41
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save PiotrZakrzewski/ffa85d966d61ae73b92f0b7d39c8959d to your computer and use it in GitHub Desktop.
Save PiotrZakrzewski/ffa85d966d61ae73b92f0b7d39c8959d to your computer and use it in GitHub Desktop.
List function calls within a Python function declaration with the ast module.
"""List function calls within a Python function declaration with the ast module."""
import ast
class PrintCalls(ast.NodeVisitor):
def visit_Call(self, node):
print(node.func.id)
code = """def fun(a:int) -> int:
b = util_fun(a)
return b"""
print(code)
print()
tree = ast.parse(code)
PrintCalls().visit(tree)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment