Skip to content

Commit 92bf919

Browse files
Issue #22581: Use more "bytes-like object" throughout the docs and comments.
2 parents 1a7b8d1 + b757c83 commit 92bf919

File tree

12 files changed

+39
-37
lines changed

12 files changed

+39
-37
lines changed

Doc/c-api/arg.rst

Lines changed: 14 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -65,19 +65,20 @@ Unless otherwise stated, buffers are not NUL-terminated.
6565
:exc:`UnicodeError` is raised.
6666

6767
.. note::
68-
This format does not accept bytes-like objects. If you want to accept
68+
This format does not accept :term:`bytes-like objects
69+
<bytes-like object>`. If you want to accept
6970
filesystem paths and convert them to C character strings, it is
7071
preferable to use the ``O&`` format with :c:func:`PyUnicode_FSConverter`
7172
as *converter*.
7273

73-
``s*`` (:class:`str`, :class:`bytes`, :class:`bytearray` or buffer compatible object) [Py_buffer]
74-
This format accepts Unicode objects as well as :term:`bytes-like object`\ s.
74+
``s*`` (:class:`str` or :term:`bytes-like object`) [Py_buffer]
75+
This format accepts Unicode objects as well as bytes-like objects.
7576
It fills a :c:type:`Py_buffer` structure provided by the caller.
7677
In this case the resulting C string may contain embedded NUL bytes.
7778
Unicode objects are converted to C strings using ``'utf-8'`` encoding.
7879

79-
``s#`` (:class:`str`, :class:`bytes` or read-only buffer compatible object) [const char \*, int or :c:type:`Py_ssize_t`]
80-
Like ``s*``, except that it doesn't accept mutable buffer-like objects
80+
``s#`` (:class:`str`, read-only :term:`bytes-like object`) [const char \*, int or :c:type:`Py_ssize_t`]
81+
Like ``s*``, except that it doesn't accept mutable bytes-like objects
8182
such as :class:`bytearray`. The result is stored into two C variables,
8283
the first one a pointer to a C string, the second one its length.
8384
The string may contain embedded null bytes. Unicode objects are converted
@@ -87,28 +88,28 @@ Unless otherwise stated, buffers are not NUL-terminated.
8788
Like ``s``, but the Python object may also be ``None``, in which case the C
8889
pointer is set to *NULL*.
8990

90-
``z*`` (:class:`str`, :class:`bytes`, :class:`bytearray`, buffer compatible object or ``None``) [Py_buffer]
91+
``z*`` (:class:`str`, :term:`bytes-like object` or ``None``) [Py_buffer]
9192
Like ``s*``, but the Python object may also be ``None``, in which case the
9293
``buf`` member of the :c:type:`Py_buffer` structure is set to *NULL*.
9394

94-
``z#`` (:class:`str`, :class:`bytes`, read-only buffer compatible object or ``None``) [const char \*, int]
95+
``z#`` (:class:`str`, read-only :term:`bytes-like object` or ``None``) [const char \*, int]
9596
Like ``s#``, but the Python object may also be ``None``, in which case the C
9697
pointer is set to *NULL*.
9798

98-
``y`` (:class:`bytes`) [const char \*]
99+
``y`` (read-only :term:`bytes-like object`) [const char \*]
99100
This format converts a bytes-like object to a C pointer to a character
100101
string; it does not accept Unicode objects. The bytes buffer must not
101102
contain embedded NUL bytes; if it does, a :exc:`TypeError`
102103
exception is raised.
103104

104-
``y*`` (:class:`bytes`, :class:`bytearray` or :term:`bytes-like object`) [Py_buffer]
105+
``y*`` (:term:`bytes-like object`) [Py_buffer]
105106
This variant on ``s*`` doesn't accept Unicode objects, only
106-
:term:`bytes-like object`\ s. **This is the recommended way to accept
107+
bytes-like objects. **This is the recommended way to accept
107108
binary data.**
108109

109-
``y#`` (:class:`bytes`) [const char \*, int]
110-
This variant on ``s#`` doesn't accept Unicode objects, only :term:`bytes-like
111-
object`\ s.
110+
``y#`` (read-only :term:`bytes-like object`) [const char \*, int]
111+
This variant on ``s#`` doesn't accept Unicode objects, only bytes-like
112+
objects.
112113

113114
``S`` (:class:`bytes`) [PyBytesObject \*]
114115
Requires that the Python object is a :class:`bytes` object, without

Doc/c-api/unicode.rst

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -556,7 +556,8 @@ APIs:
556556
Coerce an encoded object *obj* to an Unicode object and return a reference with
557557
incremented refcount.
558558
559-
:class:`bytes`, :class:`bytearray` and other char buffer compatible objects
559+
:class:`bytes`, :class:`bytearray` and other
560+
:term:`bytes-like objects <bytes-like object>`
560561
are decoded according to the given *encoding* and using the error handling
561562
defined by *errors*. Both can be *NULL* to have the interface use the default
562563
values (see the next section for details).

Doc/library/socket.rst

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1123,15 +1123,16 @@ to sockets.
11231123
Send normal and ancillary data to the socket, gathering the
11241124
non-ancillary data from a series of buffers and concatenating it
11251125
into a single message. The *buffers* argument specifies the
1126-
non-ancillary data as an iterable of buffer-compatible objects
1126+
non-ancillary data as an iterable of
1127+
:term:`bytes-like objects <bytes-like object>`
11271128
(e.g. :class:`bytes` objects); the operating system may set a limit
11281129
(:func:`~os.sysconf` value ``SC_IOV_MAX``) on the number of buffers
11291130
that can be used. The *ancdata* argument specifies the ancillary
11301131
data (control messages) as an iterable of zero or more tuples
11311132
``(cmsg_level, cmsg_type, cmsg_data)``, where *cmsg_level* and
11321133
*cmsg_type* are integers specifying the protocol level and
11331134
protocol-specific type respectively, and *cmsg_data* is a
1134-
buffer-compatible object holding the associated data. Note that
1135+
bytes-like object holding the associated data. Note that
11351136
some systems (in particular, systems without :func:`CMSG_SPACE`)
11361137
might support sending only one control message per call. The
11371138
*flags* argument defaults to 0 and has the same meaning as for

Doc/library/ssl.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1104,7 +1104,7 @@ to speed up repeated connections from the same clients.
11041104
<http://www.openssl.org/docs/ssl/SSL_CTX_load_verify_locations.html>`_.
11051105

11061106
The *cadata* object, if present, is either an ASCII string of one or more
1107-
PEM-encoded certificates or a bytes-like object of DER-encoded
1107+
PEM-encoded certificates or a :term:`bytes-like object` of DER-encoded
11081108
certificates. Like with *capath* extra lines around PEM-encoded
11091109
certificates are ignored but at least one certificate must be present.
11101110

Include/unicodeobject.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -849,7 +849,7 @@ PyAPI_FUNC(int) PyUnicode_Resize(
849849
850850
Coercion is done in the following way:
851851
852-
1. bytes, bytearray and other char buffer compatible objects are decoded
852+
1. bytes, bytearray and other bytes-like objects are decoded
853853
under the assumptions that they contain data using the UTF-8
854854
encoding. Decoding is done in "strict" mode.
855855

Lib/multiprocessing/connection.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -220,7 +220,7 @@ def recv_bytes(self, maxlength=None):
220220

221221
def recv_bytes_into(self, buf, offset=0):
222222
"""
223-
Receive bytes data into a writeable buffer-like object.
223+
Receive bytes data into a writeable bytes-like object.
224224
Return the number of bytes read.
225225
"""
226226
self._check_closed()

Modules/arraymodule.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1573,14 +1573,14 @@ frombytes(arrayobject *self, Py_buffer *buffer)
15731573
Py_ssize_t n;
15741574
if (buffer->itemsize != 1) {
15751575
PyBuffer_Release(buffer);
1576-
PyErr_SetString(PyExc_TypeError, "string/buffer of bytes required.");
1576+
PyErr_SetString(PyExc_TypeError, "a bytes-like object is required");
15771577
return NULL;
15781578
}
15791579
n = buffer->len;
15801580
if (n % itemsize != 0) {
15811581
PyBuffer_Release(buffer);
15821582
PyErr_SetString(PyExc_ValueError,
1583-
"string length not a multiple of item size");
1583+
"bytes length not a multiple of item size");
15841584
return NULL;
15851585
}
15861586
n = n / itemsize;

Modules/socketmodule.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3560,7 +3560,7 @@ sock_sendmsg(PySocketSockObject *s, PyObject *args)
35603560
for (; ndatabufs < ndataparts; ndatabufs++) {
35613561
if (!PyArg_Parse(PySequence_Fast_GET_ITEM(data_fast, ndatabufs),
35623562
"y*;sendmsg() argument 1 must be an iterable of "
3563-
"buffer-compatible objects",
3563+
"bytes-like objects",
35643564
&databufs[ndatabufs]))
35653565
goto finally;
35663566
iovs[ndatabufs].iov_base = databufs[ndatabufs].buf;
@@ -3717,12 +3717,12 @@ PyDoc_STRVAR(sendmsg_doc,
37173717
Send normal and ancillary data to the socket, gathering the\n\
37183718
non-ancillary data from a series of buffers and concatenating it into\n\
37193719
a single message. The buffers argument specifies the non-ancillary\n\
3720-
data as an iterable of buffer-compatible objects (e.g. bytes objects).\n\
3720+
data as an iterable of bytes-like objects (e.g. bytes objects).\n\
37213721
The ancdata argument specifies the ancillary data (control messages)\n\
37223722
as an iterable of zero or more tuples (cmsg_level, cmsg_type,\n\
37233723
cmsg_data), where cmsg_level and cmsg_type are integers specifying the\n\
37243724
protocol level and protocol-specific type respectively, and cmsg_data\n\
3725-
is a buffer-compatible object holding the associated data. The flags\n\
3725+
is a bytes-like object holding the associated data. The flags\n\
37263726
argument defaults to 0 and has the same meaning as for send(). If\n\
37273727
address is supplied and not None, it sets a destination address for\n\
37283728
the message. The return value is the number of bytes of non-ancillary\n\

Objects/stringlib/join.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -53,15 +53,15 @@ STRINGLIB(bytes_join)(PyObject *sep, PyObject *iterable)
5353

5454
/* Here is the general case. Do a pre-pass to figure out the total
5555
* amount of space we'll need (sz), and see whether all arguments are
56-
* buffer-compatible.
56+
* bytes-like.
5757
*/
5858
for (i = 0, nbufs = 0; i < seqlen; i++) {
5959
Py_ssize_t itemlen;
6060
item = PySequence_Fast_GET_ITEM(seq, i);
6161
if (_getbuffer(item, &buffers[i]) < 0) {
6262
PyErr_Format(PyExc_TypeError,
63-
"sequence item %zd: expected bytes, bytearray, "
64-
"or an object with the buffer interface, %.80s found",
63+
"sequence item %zd: expected a bytes-like object, "
64+
"%.80s found",
6565
i, Py_TYPE(item)->tp_name);
6666
goto error;
6767
}

Objects/unicodeobject.c

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2905,8 +2905,7 @@ PyUnicode_FromEncodedObject(PyObject *obj,
29052905
/* Retrieve a bytes buffer view through the PEP 3118 buffer interface */
29062906
if (PyObject_GetBuffer(obj, &buffer, PyBUF_SIMPLE) < 0) {
29072907
PyErr_Format(PyExc_TypeError,
2908-
"coercing to str: need bytes, bytearray "
2909-
"or buffer-like object, %.80s found",
2908+
"coercing to str: need a bytes-like object, %.80s found",
29102909
Py_TYPE(obj)->tp_name);
29112910
return NULL;
29122911
}

0 commit comments

Comments
 (0)