Skip to content

Parsing Python function arguments and type hints

Raffi Khatchadourian edited this page Nov 7, 2022 · 3 revisions
private static Set<FunctionDef> process(PythonNode pythonNode) throws ExecutionException {
    ParsedItem entry = pythonNode.entry;
    ASTEntryWithChildren ast = entry.getAstThis();
    SimpleNode simpleNode = ast.node;

    if (simpleNode instanceof FunctionDef) {
        FunctionDef function = (FunctionDef) simpleNode;
        argumentsType args = function.args;
        exprType[] annotation = args.annotation;

	if (annotation != null)
            for (exprType annot : annotation)
                if (annot != null)
                    System.out.println(annot);

        exprType[] args2 = args.args;

        if (args2 != null)
            for (exprType argType : args2)
                System.out.println(argType);
}