Commits

Amaury Forgeot d'Arc committed bfaa205 Draft

Improve error message when the buffer interface is not supported.

Comments (0)

Files changed (2)

pypy/interpreter/test/test_buffer.py

         assert space.bufferstr_w(w_hello) == 'hello world'
         assert space.bufferstr_w(space.buffer(w_hello)) == 'hello world'
         space.raises_w(space.w_TypeError, space.buffer_w, space.wrap(5))
-        space.raises_w(space.w_TypeError, space.buffer, space.wrap(5))
+        e = space.raises_w(space.w_TypeError, space.buffer, space.wrap(5))
+        message = space.unwrap(e.value.get_w_value(space))
+        assert "'int' does not support the buffer interface" == message
 
     def test_file_write(self):
         space = self.space

pypy/objspace/descroperation.py

         else:
             return space.isinstance(w_inst, w_type)
 
+    def buffer(space, w_obj):
+        w_impl = space.lookup(w_obj, '__buffer__')
+        if w_impl is None:
+            typename = space.type(w_obj).getname(space)
+            raise operationerrfmt(
+                space.w_TypeError, 
+                "'%s' does not support the buffer interface", typename)
+        return space.get_and_call_function(w_impl, w_obj)
+
 
 # helpers