8000 find_symbol_nodes signature is incorrect · Issue #19 · simonw/symbex · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

find_symbol_nodes signature is incorrect #19

New issue

Have a question about this project? Sign up for a free GitHub account to 8000 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

Closed
simonw opened this issue Jun 19, 2023 · 2 comments
Closed

find_symbol_nodes signature is incorrect #19

simonw opened this issue Jun 19, 2023 · 2 comments
Labels
bug Something isn't working

Comments

@simonw
Copy link
Owner
simonw commented Jun 19, 2023
symbex -s find_symbol_nodes
# File: symbex/lib.py Line: 8
def find_symbol_nodes(code: str, symbols)

But it should be:

symbex/symbex/lib.py

Lines 8 to 10 in 46f8a6d

def find_symbol_nodes(
code: str, symbols: Iterable[str]
) -> List[Tuple[AST, Optional[str]]]:

@simonw simonw added the bug Something isn't working label Jun 19, 2023
@simonw
Copy link
Owner Author
simonw commented Jun 19, 2023

I set ChatGPT Code Interpreter to work on this and it found a solution!

https://chat.openai.com/share/b9873d04-5978-489f-8c6b-4b948db7724d

It wrote this code (after a few iterations):

def get_annotation_str(annotation):
    """
    Helper function to return the correct string representation of a type annotation.

    Args:
        annotation (ast.expr): The AST node representing the type annotation.

    Returns:
        str: The string representation of the type annotation.
    """
    if annotation is None:
        return ""
    elif isinstance(annotation, ast.Name):
        return annotation.id
    elif isinstance(annotation, ast.Subscript):
        value = get_annotation_str(annotation.value)
        slice = get_annotation_str(annotation.slice)
        return f"{value}[{slice}]"
    elif isinstance(annotation, ast.Index):
        return get_annotation_str(annotation.value)
    elif isinstance(annotation, ast.Tuple):
        elements = ", ".join(get_annotation_str(e) for e in annotation.elts)
        return f"({elements})"
    else:
        return "?"

@simonw
Copy link
Owner Author
simonw commented Jun 19, 2023

ChatGPT also suggested https://pypi.org/project/astor/ - if I wasn't trying to avoid extra dependencies that would be a really good option.

@simonw simonw closed this as completed in 82af911 Jun 19, 2023
simonw added a commit that referenced this issue Jun 19, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

1 participant
0