Skip to content
New issue

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

Use replace_regex to replace all occurrences of "." with "/" #1315

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions integration_tests/test_import_03.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
from test_import import print_a
from test_import.test_import_1 import print_b
from test_import.import_module_01.test_import_4 import e

print(print_a())
print(print_b())
print(e)
4 changes: 2 additions & 2 deletions src/lpython/semantics/python_ast_to_asr.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3408,7 +3408,7 @@ class SymbolTableVisitor : public CommonVisitor<SymbolTableVisitor> {
// Check for the nested modules with "."
// Example: from x.y import z
if (mod_sym.find(".") != std::string::npos) {
mod_sym.replace(mod_sym.find("."), 1, "/");
mod_sym = replace(mod_sym, "[.]", "/");
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Seems like this was hard coded before.

Copy link
Collaborator Author

@Thirumalai-Shaktivel Thirumalai-Shaktivel Nov 19, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Previously, I thought replace() would replace every occurrence in the string. Now, I realize that it replaces only the first occurrence, or simply the index of the find().

if(is_directory(paths[0] + "/" + mod_sym)) {
// Directory i.e., x/y/__init__.py
paths[0] += '/' + mod_sym;
Expand All @@ -3429,7 +3429,7 @@ class SymbolTableVisitor : public CommonVisitor<SymbolTableVisitor> {
} else if (mod_sym.find(".") != std::string::npos) {
// Check for the nested modules with "."
// Example: from x.y import z
mod_sym.replace(mod_sym.find("."), 1, "/");
mod_sym = replace(mod_sym, "[.]", "/");
if(is_directory(paths[1] + "/" + mod_sym)) {
if (parent_dir != "") paths[1] += "/";
paths[1] += mod_sym;
Expand Down