Commits

Brian Kearns committed e8735af

fix len(numpy.string)

  • Participants
  • Parent commits 2ec4090

Comments (0)

Files changed (2)

pypy/module/micronumpy/interp_boxes.py

     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
 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),
 )

pypy/module/micronumpy/test/test_scalar.py

         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