1. Jeremy Thurgood
  2. pypy

Commits

Amaury Forgeot d'Arc  committed bfaa205 Draft

Improve error message when the buffer interface is not supported.

  • Participants
  • Parent commits 74a4e30
  • Branches py3k

Comments (0)

Files changed (2)

File pypy/interpreter/test/test_buffer.py

View file
  • Ignore whitespace
         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

File pypy/objspace/descroperation.py

View file
  • Ignore whitespace
         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