Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
JayGhiya opened this issue Dec 21, 2024 · 0 comments
Open

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

JayGhiya opened this issue Dec 21, 2024 · 0 comments

Comments

@JayGhiya
Copy link

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant