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

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


Author: Ronan Lamy <ronan.lamy at gmail.com>
Branch: translation-cleanup
Changeset: r57001:3c475ef86947
Date: 2012-08-15 17:55 +0100
http://bitbucket.org/pypy/pypy/changeset/3c475ef86947/

Log:	Flowspacify IMPORT_FROM

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
@@ -474,6 +474,11 @@
             if res is not None:
                 next_instr = res
 
+    def IMPORT_FROM(self, nameindex, next_instr):
+        w_name = self.getname_w(nameindex)
+        w_module = self.peekvalue()
+        self.pushvalue(self.space.import_from(w_module, w_name))
+
     def RETURN_VALUE(self, oparg, next_instr):
         w_returnvalue = self.popvalue()
         block = self.unrollstack(SReturnValue.kind)
diff --git a/pypy/objspace/flow/objspace.py b/pypy/objspace/flow/objspace.py
--- a/pypy/objspace/flow/objspace.py
+++ b/pypy/objspace/flow/objspace.py
@@ -407,6 +407,16 @@
         return self.do_operation_with_implicit_exceptions('getattr',
                 w_obj, w_name)
 
+    def import_from(self, w_module, w_name):
+        try:
+            return self.getattr(w_module, w_name)
+        except OperationError, e:
+            if e.match(self, self.w_AttributeError):
+                raise OperationError(self.w_ImportError,
+                    self.wrap("cannot import name '%s'" % w_name.value))
+            else:
+                raise
+
     def call_function(self, w_func, *args_w):
         nargs = len(args_w)
         args = argument.ArgumentsForTranslation(self, list(args_w))


More information about the pypy-commit mailing list