chapi icon indicating copy to clipboard operation
chapi copied to clipboard

Bug: Python Return types of functions are not captured.

Open JayGhiya opened this issue 1 year ago • 0 comments

None of return types are captured as per my experiments from chapi.

I tried to do a experiment using tree sitter using this logic

    def __get_return_type(self, tree) -> Optional[str]:
    # Instead of manually navigating cursor, we can do a DFS using the tree's children.
        root = tree.root_node
        stack = [root]

        while stack:
            node = stack.pop()
            if node.type == "function_definition":
                # Check children for a 'type' node
                for child in node.children:
                    if child.type == "type":
                        return child.text.decode('utf8').strip(": ")
            # Push children into stack to continue traversal
            for child in reversed(node.children):
                stack.append(child)

        return None

This works. do not know if issue is with Antlr or Chapi.

Also if there is less time as of now we could complement this with tree sitter in https://github.com/unoplat/unoplat-code-confluence post this fix https://github.com/archguard/archguard/issues/159. Thankyou

JayGhiya avatar Dec 21 '24 05:12 JayGhiya