[pypy-commit] pypy can_cast: create W_Dtype.can_cast_to()

rlamy noreply at buildbot.pypy.org
Fri Apr 24 01:39:49 CEST 2015


Author: Ronan Lamy <ronan.lamy at gmail.com>
Branch: can_cast
Changeset: r76910:9e8922d9dce5
Date: 2015-04-23 20:32 +0100
http://bitbucket.org/pypy/pypy/changeset/9e8922d9dce5/

Log:	create W_Dtype.can_cast_to()

diff --git a/pypy/module/micronumpy/arrayops.py b/pypy/module/micronumpy/arrayops.py
--- a/pypy/module/micronumpy/arrayops.py
+++ b/pypy/module/micronumpy/arrayops.py
@@ -302,7 +302,10 @@
 
 @unwrap_spec(casting=str)
 def can_cast(space, w_from, w_totype, casting='safe'):
-    return space.w_True
+    target = as_dtype(space, w_totype)
+    origin = as_dtype(space, w_from)  # XXX
+    return space.wrap(origin.can_cast_to(target))
+
 
 def as_dtype(space, w_arg):
     # roughly equivalent to CNumPy's PyArray_DescrConverter2
diff --git a/pypy/module/micronumpy/descriptor.py b/pypy/module/micronumpy/descriptor.py
--- a/pypy/module/micronumpy/descriptor.py
+++ b/pypy/module/micronumpy/descriptor.py
@@ -87,6 +87,9 @@
     def box_complex(self, real, imag):
         return self.itemtype.box_complex(real, imag)
 
+    def can_cast_to(self, other):
+        return True
+
     def coerce(self, space, w_item):
         return self.itemtype.coerce(space, self, w_item)
 


More information about the pypy-commit mailing list