Skip to content

Functions with module prefix are not mapped (Python) #104

Open
@lee-sony

Description

@lee-sony

Background

Given a typical application based on the repository pattern, I want to map function calls to make sure that data access is properly controlled.

I have a setup a project as such

.
├── infrastructure
│   └── http.py
├── main.py
└── repository
    └── user_repository.py

With the following source code (for minimal reproduction)

# infrastructure/http.py
from typing import Optional


def request(
  method: str, url: str, headers: Optional[dict] = None, body: Optional[dict] = None
) -> Optional[dict]:
  # Make an HTTP request
  pass

# repository/user_repository.py
from infrastructure import http
from infrastructure.http import request


def get_users():
  http.request("GET", "https://api.example.com/users")


def get_users2():
  request("GET", "https://api.example.com/users")

# main.py
import repository.user_repository as user_repository
from repository.user_repository import get_users2


def main():
  user_repository.get_users()
  get_users2()


main()

Logs

Code2Flow: Found 3 files from sources argument.
Code2Flow: Implicitly detected language as 'py'.
Code2Flow: Processing 3 source file(s).
Code2Flow:   ./infrastructure/http.py
Code2Flow:   ./main.py
Code2Flow:   ./repository/user_repository.py
Code2Flow: Found groups ['File: http', 'File: main', 'File: user_repository'].
Code2Flow: Found nodes ['(global)', '(global)', '(global)', 'get_users', 'get_users2', 'main', 'request'].
Code2Flow: Found calls ['get_users2()', 'http.request()', 'main()', 'request()', 'user_repository.get_users()'].
Code2Flow: Found variables ['Optional->UNKNOWN_MODULE', 'get_users2->UNKNOWN_MODULE', 'http->UNKNOWN_MODULE', 'request->UNKNOWN_MODULE', 'user_repository->UNKNOWN_MODULE'].
Code2Flow: Generating output file...
Code2Flow: Wrote output file 'out.gv' with 4 nodes and 3 edges.
Code2Flow: For better machine readability, you can also try outputting in a json format.
Code2Flow: Code2flow finished processing in 0.00 seconds.

Expected behavior

When I run code2flow ./**/*.py, I expect to see mappings for all function calls for something like this:
image

Actual behavior

However, I can only seem to get mappings that are imported directly:
image

Is this expected behavior? Or am I missing something here?

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