[pypy-commit] pypy translation-cleanup: Flowspacify IMPORT_NAME

rlamy noreply at buildbot.pypy.org
Thu Aug 30 18:38:32 CEST 2012


Author: Ronan Lamy <ronan.lamy at gmail.com>
Branch: translation-cleanup
Changeset: r57011:1f98e87fed92
Date: 2012-08-23 04:52 +0100
http://bitbucket.org/pypy/pypy/changeset/1f98e87fed92/

Log:	Flowspacify IMPORT_NAME

diff --git a/pypy/objspace/flow/flowcontext.py b/pypy/objspace/flow/flowcontext.py
--- a/pypy/objspace/flow/flowcontext.py
+++ b/pypy/objspace/flow/flowcontext.py
@@ -1,5 +1,6 @@
 import collections
 import sys
+from pypy.tool.error import FlowingError
 from pypy.interpreter.executioncontext import ExecutionContext
 from pypy.interpreter.error import OperationError
 from pypy.interpreter.pytraceback import PyTraceback
@@ -491,6 +492,21 @@
             if res is not None:
                 next_instr = res
 
+    def IMPORT_NAME(self, nameindex, next_instr):
+        space = self.space
+        modulename = self.getname_u(nameindex)
+        w_fromlist = self.popvalue()
+
+        level = self.popvalue().value
+        if level != -1:
+            raise FlowingError("Relative imports are not implemented in RPython")
+
+        w_locals = space.w_None
+        w_modulename = space.wrap(modulename)
+        w_globals = self.w_globals
+        w_obj = space.import_name(w_modulename, w_globals, w_locals, w_fromlist)
+        self.pushvalue(w_obj)
+
     def IMPORT_FROM(self, nameindex, next_instr):
         w_name = self.getname_w(nameindex)
         w_module = self.peekvalue()
diff --git a/pypy/objspace/flow/test/test_objspace.py b/pypy/objspace/flow/test/test_objspace.py
--- a/pypy/objspace/flow/test/test_objspace.py
+++ b/pypy/objspace/flow/test/test_objspace.py
@@ -701,6 +701,15 @@
             from pypy import this_does_not_exist
         py.test.raises(ImportError, 'self.codetest(f)')
 
+    def test_relative_import(self):
+        def f():
+            from ..test.test_objspace import FlowObjSpace
+        # Check that the function works in Python
+        assert f() is None
+
+        with py.test.raises(error.FlowingError):
+            self.codetest(f)
+
     def test_mergeable(self):
         def myfunc(x):
             if x:


More information about the pypy-commit mailing list