[pypy-commit] pypy py3k: Import is always absolute. This fixes many tests.
amauryfa
noreply at buildbot.pypy.org
Mon Nov 19 23:51:40 CET 2012
Author: Amaury Forgeot d'Arc <amauryfa at gmail.com>
Branch: py3k
Changeset: r59008:2ed2f6df816a
Date: 2012-11-19 21:59 +0100
http://bitbucket.org/pypy/pypy/changeset/2ed2f6df816a/
Log: Import is always absolute. This fixes many tests.
diff --git a/pypy/interpreter/astcompiler/codegen.py b/pypy/interpreter/astcompiler/codegen.py
--- a/pypy/interpreter/astcompiler/codegen.py
+++ b/pypy/interpreter/astcompiler/codegen.py
@@ -679,10 +679,7 @@
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)
@@ -721,12 +718,7 @@
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]
diff --git a/pypy/module/imp/importing.py b/pypy/module/imp/importing.py
--- a/pypy/module/imp/importing.py
+++ b/pypy/module/imp/importing.py
@@ -151,9 +151,6 @@
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:
@@ -236,10 +233,10 @@
@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"))
@@ -251,31 +248,15 @@
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
More information about the pypy-commit
mailing list