[pypy-commit] pypy jvm-improvements: Fix getattr on JvmInstanceWrapper

benol noreply at buildbot.pypy.org
Wed Jun 6 23:54:57 CEST 2012


Author: Michal Bendowski <michal at bendowski.pl>
Branch: jvm-improvements
Changeset: r55449:f98227092ae0
Date: 2012-06-05 23:02 +0200
http://bitbucket.org/pypy/pypy/changeset/f98227092ae0/

Log:	Fix getattr on JvmInstanceWrapper

diff --git a/pypy/rlib/rjvm/api.py b/pypy/rlib/rjvm/api.py
--- a/pypy/rlib/rjvm/api.py
+++ b/pypy/rlib/rjvm/api.py
@@ -90,7 +90,7 @@
                     const_cache[new_name] = JvmClassWrapper(getattr(self.__wrapped__, attr))
                 return const_cache[new_name]
             else:
-                raise TypeError("There is no class called %s in package %s" % (attr, self.__javaname__))
+                raise AttributeError("There is no class called %s in package %s" % (attr, self.__javaname__))
         elif isinstance(getattr(self.__wrapped__, attr), jpype.JPackage):
             if new_name not in const_cache:
                 const_cache[new_name] = JvmPackageWrapper(new_name)
@@ -184,7 +184,7 @@
         elif attr in self._static_field_names:
             return self._wrap_item(getattr(self.__wrapped__, attr))
         else:
-            raise TypeError(
+            raise AttributeError(
                 "There's no static member called {member_name} in class {class_name}.".format(
                     member_name=attr, class_name=self.__name__))
 
@@ -211,14 +211,12 @@
         self.__field_names = {str(f.getName()) for f in helpers._get_fields(refclass)}
 
     def __getattr__(self, attr):
-        if attr == '__wrapped__':
-            return self.__wrapped__
-        elif attr in self.__method_names:
+        if attr in self.__method_names:
             return JvmMethodWrapper(getattr(self.__wrapped__, attr))
         elif attr in self.__field_names:
             return self._wrap_item(getattr(self.__wrapped__, attr))
         else:
-            raise TypeError(
+            raise AttributeError(
                 "No instance method called {method_name} found in class {class_name}".format(
                     method_name=attr, class_name=self.__class_name))
 
diff --git a/pypy/rlib/rjvm/test/test_rjvm.py b/pypy/rlib/rjvm/test/test_rjvm.py
--- a/pypy/rlib/rjvm/test/test_rjvm.py
+++ b/pypy/rlib/rjvm/test/test_rjvm.py
@@ -29,11 +29,11 @@
     assert result == 32
 
 def test_invalid_static_member():
-    with py.test.raises(TypeError):
+    with py.test.raises(AttributeError):
         java.lang.Math.typo(42)
 
 def test_invalid_class_name():
-    with py.test.raises(TypeError):
+    with py.test.raises(AttributeError):
         java.lang.Typo()
 
 def test_class_instantiate():
@@ -54,7 +54,7 @@
 def test_invalid_method_name():
     al = java.util.ArrayList()
     al.add("test")
-    with py.test.raises(TypeError):
+    with py.test.raises(AttributeError):
         al.typo(0)
 
 def test_interpreted_reflection():
@@ -200,7 +200,7 @@
             sb = java.lang.StringBuilder()
             sb.foobar()
 
-        with py.test.raises(TypeError):
+        with py.test.raises(AttributeError):
             self.interpret(fn, [])
 
     def test_method_call_no_overload(self):
diff --git a/pypy/translator/jvm/rjvm_support/utils.py b/pypy/translator/jvm/rjvm_support/utils.py
--- a/pypy/translator/jvm/rjvm_support/utils.py
+++ b/pypy/translator/jvm/rjvm_support/utils.py
@@ -41,7 +41,7 @@
         elif self.static and name == 'class_':
             return ootypemodel.NativeRJvmInstance(helpers.RjvmJavaLangClassWrapper.java_lang_Class)._example()
         else:
-            raise TypeError(
+            raise AttributeError(
                 "No method or field called %s found in %s." % (name, self.refclass.getName()))
 
 


More information about the pypy-commit mailing list