diff options
author | R David Murray <rdmurray@bitdance.com> | 2014-10-05 15:47:01 (GMT) |
---|---|---|
committer | R David Murray <rdmurray@bitdance.com> | 2014-10-05 15:47:01 (GMT) |
commit | 861470c83607a4312d3c65bce3e18414b965e586 (patch) | |
tree | 48088d67e50d8599b00498c17b5c8b7a35b482f8 /Objects | |
parent | d577cea8ab0d929c40de93947dd68b9709607b35 (diff) | |
download | cpython-861470c83607a4312d3c65bce3e18414b965e586.zip cpython-861470c83607a4312d3c65bce3e18414b965e586.tar.gz cpython-861470c83607a4312d3c65bce3e18414b965e586.tar.bz2 |
#16518: Bring error messages in harmony with docs ("bytes-like object")
Some time ago we changed the docs to consistently use the term 'bytes-like
object' in all the contexts where bytes, bytearray, memoryview, etc are used.
This patch (by Ezio Melotti) completes that work by changing the error
messages that previously reported that certain types did "not support the
buffer interface" to instead say that a bytes-like object is required. (The
glossary entry for bytes-like object references the discussion of the buffer
protocol in the docs.)
Diffstat (limited to 'Objects')
-rw-r--r-- | Objects/abstract.c | 13 | ||||
-rw-r--r-- | Objects/bytearrayobject.c | 2 | ||||
-rw-r--r-- | Objects/bytes_methods.c | 2 | ||||
-rw-r--r-- | Objects/bytesobject.c | 2 | ||||
-rw-r--r-- | Objects/longobject.c | 4 | ||||
-rw-r--r-- | Objects/memoryobject.c | 2 |
6 files changed, 11 insertions, 14 deletions
diff --git a/Objects/abstract.c b/Objects/abstract.c index 177c34a..323c985 100644 --- a/Objects/abstract.c +++ b/Objects/abstract.c @@ -260,8 +260,7 @@ PyObject_AsCharBuffer(PyObject *obj, pb = obj->ob_type->tp_as_buffer; if (pb == NULL || pb->bf_getbuffer == NULL) { PyErr_SetString(PyExc_TypeError, - "expected bytes, bytearray " - "or buffer compatible object"); + "expected a bytes-like object"); return -1; } if ((*pb->bf_getbuffer)(obj, &view, PyBUF_SIMPLE)) return -1; @@ -306,7 +305,7 @@ int PyObject_AsReadBuffer(PyObject *obj, if (pb == NULL || pb->bf_getbuffer == NULL) { PyErr_SetString(PyExc_TypeError, - "expected an object with a buffer interface"); + "expected a bytes-like object"); return -1; } @@ -336,7 +335,7 @@ int PyObject_AsWriteBuffer(PyObject *obj, pb->bf_getbuffer == NULL || ((*pb->bf_getbuffer)(obj, &view, PyBUF_WRITABLE) != 0)) { PyErr_SetString(PyExc_TypeError, - "expected an object with a writable buffer interface"); + "expected a writable bytes-like object"); return -1; } @@ -355,7 +354,7 @@ PyObject_GetBuffer(PyObject *obj, Py_buffer *view, int flags) { if (!PyObject_CheckBuffer(obj)) { PyErr_Format(PyExc_TypeError, - "'%.100s' does not support the buffer interface", + "a bytes-like object is required, not '%.100s'", Py_TYPE(obj)->tp_name); return -1; } @@ -530,8 +529,8 @@ int PyObject_CopyData(PyObject *dest, PyObject *src) if (!PyObject_CheckBuffer(dest) || !PyObject_CheckBuffer(src)) { PyErr_SetString(PyExc_TypeError, - "both destination and source must have the "\ - "buffer interface"); + "both destination and source must be "\ + "bytes-like objects"); return -1; } diff --git a/Objects/bytearrayobject.c b/Objects/bytearrayobject.c index f6f370d..84447bc 100644 --- a/Objects/bytearrayobject.c +++ b/Objects/bytearrayobject.c @@ -87,7 +87,7 @@ _getbuffer(PyObject *obj, Py_buffer *view) if (buffer == NULL || buffer->bf_getbuffer == NULL) { PyErr_Format(PyExc_TypeError, - "Type %.100s doesn't support the buffer API", + "a bytes-like object is required, not '%.100s'", Py_TYPE(obj)->tp_name); return -1; } diff --git a/Objects/bytes_methods.c b/Objects/bytes_methods.c index 5314ab4..1cf20c9 100644 --- a/Objects/bytes_methods.c +++ b/Objects/bytes_methods.c @@ -371,7 +371,7 @@ _getbuffer(PyObject *obj, Py_buffer *view) if (buffer == NULL || buffer->bf_getbuffer == NULL) { PyErr_Format(PyExc_TypeError, - "Type %.100s doesn't support the buffer API", + "a bytes-like object is required, not '%.100s'", Py_TYPE(obj)->tp_name); return -1; } diff --git a/Objects/bytesobject.c b/Objects/bytesobject.c index 87c0a25..ff99f93 100644 --- a/Objects/bytesobject.c +++ b/Objects/bytesobject.c @@ -29,7 +29,7 @@ _getbuffer(PyObject *obj, Py_buffer *view) if (bufferprocs == NULL || bufferprocs->bf_getbuffer == NULL) { PyErr_Format(PyExc_TypeError, - "Type %.100s doesn't support the buffer API", + "a bytes-like object is required, not '%.100s'", Py_TYPE(obj)->tp_name); return -1; } diff --git a/Objects/longobject.c b/Objects/longobject.c index bb2eb17..27bee50 100644 --- a/Objects/longobject.c +++ b/Objects/longobject.c @@ -4873,9 +4873,7 @@ PyDoc_STRVAR(long_from_bytes_doc, \n\ Return the integer represented by the given array of bytes.\n\ \n\ -The bytes argument must either support the buffer protocol or be an\n\ -iterable object producing bytes. Bytes and bytearray are examples of\n\ -built-in objects that support the buffer protocol.\n\ +The bytes argument must be a bytes-like object (e.g. bytes or bytearray).\n\ \n\ The byteorder argument determines the byte order used to represent the\n\ integer. If byteorder is 'big', the most significant byte is at the\n\ diff --git a/Objects/memoryobject.c b/Objects/memoryobject.c index 5148ce6..935da04 100644 --- a/Objects/memoryobject.c +++ b/Objects/memoryobject.c @@ -792,7 +792,7 @@ PyMemoryView_FromObject(PyObject *v) } PyErr_Format(PyExc_TypeError, - "memoryview: %.200s object does not have the buffer interface", + "memoryview: a bytes-like object is required, not '%.200s'", Py_TYPE(v)->tp_name); return NULL; } |