[pypy-svn] r25303 - in pypy/dist/pypy/rpython: ootypesystem ootypesystem/test test

nik at codespeak.net nik at codespeak.net
Tue Apr 4 17:18:01 CEST 2006


Author: nik
Date: Tue Apr  4 17:17:59 2006
New Revision: 25303

Modified:
   pypy/dist/pypy/rpython/ootypesystem/ootype.py
   pypy/dist/pypy/rpython/ootypesystem/test/test_oolist.py
   pypy/dist/pypy/rpython/test/test_rpbc.py
Log:
(nik, pedronis around)
skip a new rpbc test for ootypesystem, it uses lists and strings which
we don't fully support, yet. but this test uncovered that we are
missing a null list, added that.


Modified: pypy/dist/pypy/rpython/ootypesystem/ootype.py
==============================================================================
--- pypy/dist/pypy/rpython/ootypesystem/ootype.py	(original)
+++ pypy/dist/pypy/rpython/ootypesystem/ootype.py	Tue Apr  4 17:17:59 2006
@@ -174,6 +174,7 @@
 
     def __init__(self, ITEMTYPE):
         self._ITEMTYPE = ITEMTYPE
+        self._null = _null_list(self)
 
         # This defines the abstract list interface that backends will have
         # to map to their native list implementations.
@@ -199,6 +200,9 @@
     def _example(self):
         return new(self)
 
+    def _defl(self):
+        return self._null
+
 # ____________________________________________________________
 
 class _class(object):
@@ -277,34 +281,36 @@
             return 0   # for all null instances
 
 
-class _null_instance(_instance):
+def _null_mixin(klass):
+    class mixin(object):
 
-    def __init__(self, INSTANCE):
-        self.__dict__["_TYPE"] = INSTANCE
-
-    def __str__(self):
-        return '%r null inst' % (self._TYPE._name,)
+        def __str__(self):
+            return '%r null inst' % (self._TYPE._name,)
 
-    def __getattribute__(self, name):
-        if name.startswith("_"):
-            return object.__getattribute__(self, name)
-    
-        self._TYPE._check_field(name)
+        def __getattribute__(self, name):
+            if name.startswith("_"):
+                return object.__getattribute__(self, name)
         
-        raise RuntimeError("Access to field in null object")
+            raise RuntimeError("Access to field in null object")
 
-    def __setattr__(self, name, value):
-        _instance.__setattr__(self, name, value)
+        def __setattr__(self, name, value):
+            klass.__setattr__(self, name, value)
 
-        raise RuntimeError("Assignment to field in null object")
+            raise RuntimeError("Assignment to field in null object")
 
-    def __nonzero__(self):
-        return False
+        def __nonzero__(self):
+            return False
 
-    def __eq__(self, other):
-        if not isinstance(other, _instance):
-            raise TypeError("comparing an _instance with %r" % (other,))
-        return not other
+        def __eq__(self, other):
+            if not isinstance(other, klass):
+                raise TypeError("comparing an %s with %r" % (klass.__name__, other))
+            return not other
+    return mixin
+
+class _null_instance(_null_mixin(_instance), _instance):
+
+    def __init__(self, INSTANCE):
+        self.__dict__["_TYPE"] = INSTANCE
 
 
 class _view(object):
@@ -486,6 +492,11 @@
         assert typeOf(index) == Signed
         self._list[index] = item
 
+class _null_list(_null_mixin(_list), _list):
+
+    def __init__(self, LIST):
+        self.__dict__["_TYPE"] = LIST 
+
 def new(TYPE):
     if isinstance(TYPE, Instance):
         return make_instance(TYPE)

Modified: pypy/dist/pypy/rpython/ootypesystem/test/test_oolist.py
==============================================================================
--- pypy/dist/pypy/rpython/ootypesystem/test/test_oolist.py	(original)
+++ pypy/dist/pypy/rpython/ootypesystem/test/test_oolist.py	Tue Apr  4 17:17:59 2006
@@ -32,6 +32,11 @@
     py.test.raises(IndexError, l.getitem, 0)
     py.test.raises(IndexError, l.setitem, 0, 1)
 
+def test_null():
+    LT = List(Signed)
+    n = null(LT)
+    py.test.raises(RuntimeError, "n.append(0)")
+
 class TestInterpreted:
 
     def test_append_length(self):

Modified: pypy/dist/pypy/rpython/test/test_rpbc.py
==============================================================================
--- pypy/dist/pypy/rpython/test/test_rpbc.py	(original)
+++ pypy/dist/pypy/rpython/test/test_rpbc.py	Tue Apr  4 17:17:59 2006
@@ -968,6 +968,8 @@
             assert res.item1 == f(i)[1]
 
     def test_pbc_imprecise_attrfamily(self):
+        if self.ts == "ootype":
+            py.test.skip("fix me if ootype fully supports lists")
         fr1 = Freezing(); fr1.x = 5; fr1.y = [8]
         fr2 = Freezing(); fr2.x = 6; fr2.y = ["string"]
         def head(fr):



More information about the Pypy-commit mailing list