[pypy-commit] pypy numpy-dtype-strings: Change string special case to use call_function instead

jterrace noreply at buildbot.pypy.org
Mon Dec 12 22:52:55 CET 2011


Author: Jeff Terrace <jterrace at gmail.com>
Branch: numpy-dtype-strings
Changeset: r50450:ed24df405fd9
Date: 2011-12-12 16:02 -0500
http://bitbucket.org/pypy/pypy/changeset/ed24df405fd9/

Log:	Change string special case to use call_function instead

diff --git a/pypy/module/micronumpy/types.py b/pypy/module/micronumpy/types.py
--- a/pypy/module/micronumpy/types.py
+++ b/pypy/module/micronumpy/types.py
@@ -191,16 +191,7 @@
     _mixin_ = True
 
     def _coerce(self, space, w_item):
-        if space.isinstance_w(w_item, space.w_str):
-            try:
-                val = int(space.str_w(space.str(w_item)))
-            except ValueError:
-                raise OperationError(space.w_ValueError, space.wrap("Invalid integer value"))
-            if not isinstance(val, int):
-                raise OperationError(space.w_OverflowError, space.wrap("Value out of range"))
-        else:
-            val = space.int_w(space.int(w_item))
-        return self.box(val)
+        return self.box(space.int_w(space.call_function(space.w_int, w_item)))
 
     def str_format(self, box):
         value = self.unbox(box)
@@ -298,14 +289,7 @@
     _mixin_ = True
 
     def _coerce(self, space, w_item):
-        if space.isinstance_w(w_item, space.w_str):
-            try:
-                val = float(space.str_w(space.str(w_item)))
-            except ValueError:
-                raise OperationError(space.w_ValueError, space.wrap("Invalid float value"))
-        else:
-            val = space.float_w(space.float(w_item))
-        return self.box(val)
+        return self.box(space.float_w(space.call_function(space.w_float, w_item)))
 
     def str_format(self, box):
         value = self.unbox(box)


More information about the pypy-commit mailing list