Skip to content

Commit

Permalink
Fix bug with determining whether a module is "local."
Browse files Browse the repository at this point in the history
The old code didn't consider the full path of the module, which is what
is contained in `localModules`. But, it still doesn't do what I think it
should do, which makes me believe that the generated CAst is incorrect.
  • Loading branch information
khatchad committed Mar 23, 2024
1 parent 0e6c95b commit 0f6872d
Showing 1 changed file with 6 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -83,14 +83,14 @@ public CAstNode visitImportFrom(ImportFrom importFrom) throws Exception {
String moduleName = s.get();
LOGGER.finer("Module name from " + importFrom + " is: " + moduleName + ".");

if (!localModules.contains(moduleName + ".py")) {
if (!isLocalModule(moduleName)) {
LOGGER.finer("Module: " + moduleName + ".py" + " isn't local.");
moduleName = s.get() + "/__init__";
} else LOGGER.finer("Module: " + moduleName + ".py" + " is local.");

LOGGER.finer("Module name from " + importFrom + " is: " + moduleName + ".");

if (localModules.contains(moduleName + ".py")) {
if (isLocalModule(moduleName)) {
LOGGER.finer("Module: " + moduleName + ".py" + " is local.");

String yuck = moduleName;
Expand Down Expand Up @@ -174,4 +174,8 @@ public static void main(String[] args) throws Exception {
protected Reader getReader() throws IOException {
return new InputStreamReader(fileName.getInputStream());
}

private boolean isLocalModule(String moduleName) {
return localModules.stream().anyMatch(lm -> lm.endsWith(moduleName + ".py"));
}
}

0 comments on commit 0f6872d

Please sign in to comment.