[pypy-svn] r73841 - in pypy/trunk/pypy/interpreter: . test

benjamin at codespeak.net benjamin at codespeak.net
Sat Apr 17 21:27:49 CEST 2010


Author: benjamin
Date: Sat Apr 17 21:27:47 2010
New Revision: 73841

Modified:
   pypy/trunk/pypy/interpreter/baseobjspace.py
   pypy/trunk/pypy/interpreter/test/test_objspace.py
Log:
introduce space.isinstance_w shortuct

Modified: pypy/trunk/pypy/interpreter/baseobjspace.py
==============================================================================
--- pypy/trunk/pypy/interpreter/baseobjspace.py	(original)
+++ pypy/trunk/pypy/interpreter/baseobjspace.py	Sat Apr 17 21:27:47 2010
@@ -877,6 +877,9 @@
         w_objtype = self.type(w_obj)
         return self.issubtype(w_objtype, w_type)
 
+    def isinstance_w(self, w_obj, w_type):
+        return self.is_true(self.isinstance(w_obj, w_type))
+
     # The code below only works
     # for the simple case (new-style instance).
     # These methods are patched with the full logic by the __builtin__

Modified: pypy/trunk/pypy/interpreter/test/test_objspace.py
==============================================================================
--- pypy/trunk/pypy/interpreter/test/test_objspace.py	(original)
+++ pypy/trunk/pypy/interpreter/test/test_objspace.py	Sat Apr 17 21:27:47 2010
@@ -12,7 +12,18 @@
 INT32_MAX = 2147483648
 
 
-class TestObjSpace: 
+class TestObjSpace:
+
+    def test_isinstance(self):
+        space = self.space
+        w_i = space.wrap(4)
+        w_result = space.isinstance(w_i, space.w_int)
+        assert space.is_true(w_result)
+        assert space.isinstance_w(w_i, space.w_int)
+        w_result = space.isinstance(w_i, space.w_str)
+        assert not space.is_true(w_result)
+        assert not space.isinstance_w(w_i, space.w_str)
+
     def test_newlist(self):
         w = self.space.wrap
         l = range(10)



More information about the Pypy-commit mailing list