Commits

Amaury Forgeot d'Arc committed 2ec74dd

Don't use sys.path when loading a submodule

  • Participants
  • Parent commits 05ae664
  • Branches import-builtin

Comments (0)

Files changed (2)

pypy/module/imp/importing.py

     w_mod = None
     parts = modulename.split('.')
     prefix = []
-    # it would be nice if we could do here: w_path = space.sys.w_path
-    # instead:
-    w_path = space.sys.get('path') 
+    w_path = None
 
     first = None
     level = 0
 
 def find_in_meta_path(space, w_modulename, w_path):
     assert w_modulename is not None
+    if w_path is None:
+        w_path = space.w_None
     for w_hook in space.unpackiterable(space.sys.get("meta_path")):
         w_loader = space.call_method(w_hook, "find_module",
                                      w_modulename, w_path)
     # XXX Check for frozen modules?
     #     when w_path is a string
 
-    # check the builtin modules
-    if modulename in space.builtin_modules:
-        return FindInfo(C_BUILTIN, modulename, None)
+    if w_path is None:
+        # check the builtin modules
+        if modulename in space.builtin_modules:
+            return FindInfo(C_BUILTIN, modulename, None)
+        w_path = space.sys.get('path')
 
     # XXX check frozen modules?
     #     when w_path is null
     modulename = '.'.join(prefix + [partname])
     w_modulename = w(modulename)
     w_mod = check_sys_modules(space, w_modulename)
+
     if w_mod is not None:
         if not space.is_w(w_mod, space.w_None):
             return w_mod
-    else:
+    elif not prefix or w_path is not None:
         find_info = find_module(
             space, modulename, w_modulename, partname, w_path)
 
                 space.w_ImportError,
                 space.wrap("reload(): parent %s not in sys.modules" % (
                     parent_name,)))
-        w_path = space.getitem(w_parent, space.wrap("__path"))
+        w_path = space.getitem(w_parent, space.wrap("__path__"))
     else:
-        w_path = space.sys.get('path')
+        w_path = None
 
     find_info = find_module(
         space, modulename, w_modulename, subname, w_path)
     try:
         return load_module(space, w_modulename, find_info, reuse=True)
     finally:
-        find_info.stream.close()
+        if find_info.stream:
+            find_info.stream.close()
 
 
 # __________________________________________________________________

pypy/module/imp/interp_imp.py

 def find_module(space, w_name, w_path=None):
     name = space.str_w(w_name)
     if space.is_w(w_path, space.w_None):
-        w_path = space.sys.get('path')
+        w_path = None
 
     find_info = importing.find_module(
         space, name, w_name, name, w_path, use_loader=False)