Skip to content

Bug: Python Return types of functions are not captured. #34

@JayGhiya

Description

@JayGhiya

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 archguard/archguard#159. Thankyou

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions