[pypy-commit] pypy default: fix len(numpy.string)

bdkearns noreply at buildbot.pypy.org
Wed Dec 18 04:25:46 CET 2013


Author: Brian Kearns <bdkearns at gmail.com>
Branch: 
Changeset: r68457:e8735afef7f7
Date: 2013-12-17 22:25 -0500
http://bitbucket.org/pypy/pypy/changeset/e8735afef7f7/

Log:	fix len(numpy.string)

diff --git a/pypy/module/micronumpy/interp_boxes.py b/pypy/module/micronumpy/interp_boxes.py
--- a/pypy/module/micronumpy/interp_boxes.py
+++ b/pypy/module/micronumpy/interp_boxes.py
@@ -483,6 +483,9 @@
     def convert_to(self, space, dtype):
         return dtype.coerce(space, space.wrap(self.raw_str()))
 
+    def descr_len(self, space):
+        return space.len(self.item(space))
+
 class W_StringBox(W_CharacterBox):
     def descr__new__string_box(space, w_subtype, w_arg):
         from pypy.module.micronumpy.interp_dtype import new_string_dtype
@@ -756,9 +759,11 @@
 W_StringBox.typedef = TypeDef("string_", (W_CharacterBox.typedef, str_typedef),
     __module__ = "numpy",
     __new__ = interp2app(W_StringBox.descr__new__string_box.im_func),
+    __len__ = interp2app(W_StringBox.descr_len),
 )
 
 W_UnicodeBox.typedef = TypeDef("unicode_", (W_CharacterBox.typedef, unicode_typedef),
     __module__ = "numpy",
     __new__ = interp2app(W_UnicodeBox.descr__new__unicode_box.im_func),
+    __len__ = interp2app(W_UnicodeBox.descr_len),
 )
diff --git a/pypy/module/micronumpy/test/test_scalar.py b/pypy/module/micronumpy/test/test_scalar.py
--- a/pypy/module/micronumpy/test/test_scalar.py
+++ b/pypy/module/micronumpy/test/test_scalar.py
@@ -32,6 +32,9 @@
         assert bin(np.int32(11)) == '0b1011'
         exc = raises(TypeError, "bin(np.float32(11.6))")
         assert "index" in exc.value.message
+        exc = raises(TypeError, "len(np.int32(11))")
+        assert "has no len" in exc.value.message
+        assert len(np.string_('123')) == 3
 
     def test_pickle(self):
         from numpypy import dtype, zeros


More information about the pypy-commit mailing list