[pypy-commit] pypy translation-cleanup: Simplify import_from() logic

rlamy noreply at buildbot.pypy.org
Fri Sep 21 18:26:01 CEST 2012


Author: Ronan Lamy <ronan.lamy at gmail.com>
Branch: translation-cleanup
Changeset: r57454:9fd31c82c2cf
Date: 2012-09-21 17:25 +0100
http://bitbucket.org/pypy/pypy/changeset/9fd31c82c2cf/

Log:	Simplify import_from() logic

	* Copy and adapt getattr() code, so that import_from() doesn't rely
	on repackaging OperationThatShouldNotBePropagatedError

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
@@ -352,14 +352,19 @@
         return self.wrap(mod)
 
     def import_from(self, w_module, w_name):
+        assert isinstance(w_module, Constant)
+        assert isinstance(w_name, Constant)
+        # handle sys
+        if w_module in self.not_really_const:
+            const_w = self.not_really_const[w_obj]
+            if w_name not in const_w:
+                return self.do_operation_with_implicit_exceptions('getattr',
+                                                                w_obj, w_name)
         try:
-            return self.getattr(w_module, w_name)
-        except FSException, e:
-            if e.match(self, self.w_AttributeError):
-                raise FSException(self.w_ImportError,
-                    self.wrap("cannot import name '%s'" % w_name.value))
-            else:
-                raise
+            return self.wrap(getattr(w_module.value, w_name.value))
+        except AttributeError:
+            raise FSException(self.w_ImportError,
+                self.wrap("cannot import name '%s'" % w_name.value))
 
     def call_function(self, w_func, *args_w):
         nargs = len(args_w)


More information about the pypy-commit mailing list