Commits

Amaury Forgeot d'Arc committed 2ed2f6d

Import is always absolute. This fixes many tests.

Comments (0)

Files changed (2)

pypy/interpreter/astcompiler/codegen.py

         self.update_position(imp.lineno, True)
         for alias in imp.names:
             assert isinstance(alias, ast.alias)
-            if self.compile_info.flags & consts.CO_FUTURE_ABSOLUTE_IMPORT:
-                level = 0
-            else:
-                level = -1
+            level = 0
             self.load_const(self.space.wrap(level))
             self.load_const(self.space.w_None)
             self.emit_op_name(ops.IMPORT_NAME, self.names, alias.name)
                         self.error("not a chance", imp)
                     self.error("future feature %s is not defined" %
                                (alias.name,), imp)
-        if imp.level == 0 and \
-                not self.compile_info.flags & consts.CO_FUTURE_ABSOLUTE_IMPORT:
-            level = -1
-        else:
-            level = imp.level
-        self.load_const(space.wrap(level))
+        self.load_const(space.wrap(imp.level))
         names_w = [None]*len(imp.names)
         for i in range(len(imp.names)):
             alias = imp.names[i]

pypy/module/imp/importing.py

 
     if ctxt_package is not None:
         # __package__ is set, so use it
-        if ctxt_package == '' and level < 0:
-            return None, 0
-
         dot_position = _get_dot_position(ctxt_package, level - 1)
         if dot_position < 0:
             if len(ctxt_package) == 0:
 
 @unwrap_spec(name='str0', level=int)
 def importhook(space, name, w_globals=None,
-               w_locals=None, w_fromlist=None, level=-1):
+               w_locals=None, w_fromlist=None, level=0):
     modulename = name
     space.timer.start_name("importhook", modulename)
-    if not modulename and level < 0:
+    if not modulename and level == 0:
         raise OperationError(
             space.w_ValueError,
             space.wrap("Empty module name"))
         fromlist_w = None
 
     rel_modulename = None
-    if (level != 0 and
+    if (level > 0 and
         w_globals is not None and
         space.isinstance_w(w_globals, space.w_dict)):
 
         rel_modulename, rel_level = _get_relative_name(space, modulename, level, w_globals)
 
         if rel_modulename:
-            # if no level was set, ignore import errors, and
-            # fall back to absolute import at the end of the
-            # function.
-            if level == -1:
-                # This check is a fast path to avoid redoing the
-                # following absolute_import() in the common case
-                w_mod = check_sys_modules_w(space, rel_modulename)
-                if w_mod is not None and space.is_w(w_mod, space.w_None):
-                    # if we already find space.w_None, it means that we
-                    # already tried and failed and fell back to the
-                    # end of this function.
-                    w_mod = None
-                else:
-                    w_mod = absolute_import(space, rel_modulename, rel_level,
-                                            fromlist_w, tentative=True)
-            else:
-                w_mod = absolute_import(space, rel_modulename, rel_level,
-                                        fromlist_w, tentative=False)
+            w_mod = absolute_import(space, rel_modulename, rel_level,
+                                    fromlist_w, tentative=False)
             if w_mod is not None:
                 space.timer.stop_name("importhook", modulename)
                 return w_mod
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.