Last active
April 5, 2021 07:41
-
-
Save PiotrZakrzewski/ffa85d966d61ae73b92f0b7d39c8959d to your computer and use it in GitHub Desktop.
List function calls within a Python function declaration with the ast module.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
"""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