Commit 9ebceb76 authored by Kevin Modzelewski's avatar Kevin Modzelewski

Fix path_hooks issue

Don't pass path to this version of find_module (unlike finders in meta_path).
parent 1216112d
......@@ -231,10 +231,9 @@ SearchResult findModule(const std::string& name, const std::string& full_name, B
return SearchResult("", SearchResult::SEARCH_ERROR);
if (importer != None) {
auto path_pass = path_list ? path_list : None;
Box* loader = callattr(importer, &find_module_str,
CallattrFlags({.cls_only = false, .null_on_nonexistent = false }), ArgPassSpec(2),
boxString(full_name), path_pass, NULL, NULL, NULL);
CallattrFlags({.cls_only = false, .null_on_nonexistent = false }), ArgPassSpec(1),
boxString(full_name), NULL, NULL, NULL, NULL);
if (loader != None)
return SearchResult(loader);
}
......@@ -489,7 +488,7 @@ Box* importModuleLevel(const std::string& name, Box* globals, Box* from_imports,
std::string _name = name;
Box* head;
bool again = loadNext(parent, level < 0 ? NULL : parent, _name, buf, &head);
bool again = loadNext(parent, level < 0 ? None : parent, _name, buf, &head);
if (head == NULL)
return NULL;
......
......@@ -20,13 +20,40 @@ class Finder(object):
print "find", fullname, path
return Loader()
class Finder2(object):
def __new__(cls, path):
print "new2", path
return object.__new__(cls)
def __init__(self, path):
self.path = path
def find_module(self, fullname):
print "find2", self.path, fullname
return None
# Fill the importer cache, so that we don't have to worry about the exact
# sys.path:
try:
import a.b.test
except ImportError, e:
print "caught import error"
# The error CPython gives here is "No module named a.b.test". Both we and PyPy think this
# is wrong and that the error should be "No module named a".
# So unfortunately we can't print out the error message.
print "caught import error 1"
sys.path_hooks.append(Finder2)
try:
import a.b.test
except ImportError, e:
print "caught import error 2"
sys.path.append("/my_magic_directory")
try:
import a.b.test
except ImportError, e:
print "caught import error 3"
sys.meta_path.append(Finder())
import a
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment