Skip to content

Python-SDK does not handle import aliases #124

Open
@rofrano

Description

@rofrano

Describe the bug

The Python-sdk does not handle an import that has been renamed to an alias such as import pandas as pd.

To Reproduce

Steps to reproduce the behavior:

  1. Run this code:
from cldk.analysis.python.treesitter import PythonSitter

code = """
import io
from flask import Flask
import pandas as pd

def hello():
  print("Hello!")
"""

if __name__ == "__main__":
    python_sitter = PythonSitter()

    print("Statements:\n")
    import_statements = python_sitter.get_all_imports(code)
    for statement in import_statements:
        print(statement)

    print("\nDetails:\n")
    import_details = python_sitter.get_all_imports_details(code)
    for detail in import_details:
        print(detail)

Expected behavior

I expect to get all of the imports parsed correctly from the get_all_imports_details() method.

Instead I got this output:

Statements:

import io
import pandas as pd
from flask import Flask

Details:

from_statement='' imports=['io']
from_statement='' imports=[]
from_statement='flask' imports=['Flask']

Notice the from_statement='' imports=[] in the output instead of the pandas import.

Logs
If applicable, add logs to help explain your problem.

Additional context
Add any other context about the problem here.

Metadata

Metadata

Assignees

Labels

bugSomething isn't working

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions