summaryrefslogtreecommitdiff
path: root/Objects
diff options
context:
space:
mode:
authorR David Murray <rdmurray@bitdance.com>2014-10-05 11:47:01 -0400
committerR David Murray <rdmurray@bitdance.com>2014-10-05 11:47:01 -0400
commit61d5d0b23f4fbcd7648478914717d681abe592e6 (patch)
treee5234e1012f2f6623da61b78389b630f33172182 /Objects
parent7b7365c77d0fab80fa25ae86dcc6cac0345fab95 (diff)
downloadcpython-61d5d0b23f4fbcd7648478914717d681abe592e6.tar.gz
#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.c13
-rw-r--r--Objects/bytearrayobject.c2
-rw-r--r--Objects/bytes_methods.c2
-rw-r--r--Objects/bytesobject.c2
-rw-r--r--Objects/longobject.c4
-rw-r--r--Objects/memoryobject.c2
6 files changed, 11 insertions, 14 deletions
diff --git a/Objects/abstract.c b/Objects/abstract.c
index 177c34a4a4..323c985b3e 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 f6f370d42c..84447bc7ee 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 5314ab4c18..1cf20c97d3 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 87c0a25608..ff99f936aa 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 bb2eb17a09..27bee50b8c 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 5148ce6bef..935da04cd7 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;
}