Fix module prefix function mapping for Python imports #108
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Fixes #104 - Functions with module prefix are not mapped correctly when using imports like
from infrastructure import http
followed by calls likehttp.request()
.Problem
When analyzing Python code with nested module imports, code2flow was not properly connecting function calls that use module prefixes. For example:
Before the fix:
http->UNKNOWN_MODULE
http.request()
Root Cause
The issue was in the
_resolve_str_variable()
function inmodel.py
. When processingfrom infrastructure import http
, it creates a variable with:token = "http"
points_to = "infrastructure.http"
But the file
infrastructure/http.py
hasimport_tokens = ["http"]
. The function only checked for exact matches between"infrastructure.http"
and["http"]
, which failed.Solution
Enhanced
_resolve_str_variable()
to include a fallback check for module path matching:This allows
"infrastructure.http"
to match files with import token"http"
when the variable path ends with".http"
.Results
After the fix:
http->http
(properly resolved)Testing
module_prefix_imports
to prevent regressiontwo_file_simple
,import_paths
, etc.)The fix is minimal, targeted, and maintains backward compatibility while solving the core mapping issue for module-prefixed function calls.
Warning
Firewall rules blocked me from connecting to one or more addresses
I tried to connect to the following addresses, but was blocked by firewall rules:
esm.ubuntu.com
/usr/lib/apt/methods/https
(dns block)If you need me to access, download, or install something from one of these locations, you can either:
💬 Share your feedback on Copilot coding agent for the chance to win a $200 gift card! Click here to start the survey.