[pypy-commit] pypy numpy-dtype-alt: clean up the class hierarchy

alex_gaynor noreply at buildbot.pypy.org
Mon Aug 15 16:18:50 CEST 2011


Author: Alex Gaynor <alex.gaynor at gmail.com>
Branch: numpy-dtype-alt
Changeset: r46521:ba8fffaaca19
Date: 2011-08-15 09:22 -0500
http://bitbucket.org/pypy/pypy/changeset/ba8fffaaca19/

Log:	clean up the class hierarchy

diff --git a/pypy/module/micronumpy/interp_dtype.py b/pypy/module/micronumpy/interp_dtype.py
--- a/pypy/module/micronumpy/interp_dtype.py
+++ b/pypy/module/micronumpy/interp_dtype.py
@@ -63,6 +63,7 @@
         return self.Box(self.unerase(storage)[i])
 
     def setitem(self, storage, i, item):
+        assert isinstance(item, self.Box)
         self.unerase(storage)[i] = item.val
 
     def setitem_w(self, space, storage, i, w_item):
@@ -186,22 +187,21 @@
     return lltype.Ptr(lltype.Array(T, hints={"nolength": True}))
 
 class BaseBox(object):
-    _mixin_ = True
+    pass
 
-    def __init__(self, val):
-        if self.valtype is not None:
-            assert isinstance(val, self.valtype)
-        self.val = val
+def make_box(TP, valtype=None):
+    class Box(BaseBox):
+        def __init__(self, val):
+            if valtype is not None:
+                assert isinstance(val, valtype  )
+            self.val = val
 
-    def wrap(self, space):
-        return space.wrap(self.val)
+        def wrap(self, space):
+            return space.wrap(self.val)
 
-    def convert_to(self, dtype):
-        return dtype.adapt_val(self.val)
+        def convert_to(self, dtype):
+            return dtype.adapt_val(self.val)
 
-def make_box(TP, v=None):
-    class Box(BaseBox, object):
-        valtype = v
     Box.__name__ = "%sBox" % TP.TO.OF._name
     return Box
 


More information about the pypy-commit mailing list