Author: Amaury Forgeot d'Arc <amaur...@gmail.com> Branch: py3k Changeset: r57867:bfaa20565278 Date: 2012-10-07 10:49 +0200 http://bitbucket.org/pypy/pypy/changeset/bfaa20565278/
Log: Improve error message when the buffer interface is not supported. diff --git a/pypy/interpreter/test/test_buffer.py b/pypy/interpreter/test/test_buffer.py --- a/pypy/interpreter/test/test_buffer.py +++ b/pypy/interpreter/test/test_buffer.py @@ -19,7 +19,9 @@ 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 diff --git a/pypy/objspace/descroperation.py b/pypy/objspace/descroperation.py --- a/pypy/objspace/descroperation.py +++ b/pypy/objspace/descroperation.py @@ -473,6 +473,15 @@ 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 _______________________________________________ pypy-commit mailing list pypy-commit@python.org http://mail.python.org/mailman/listinfo/pypy-commit