Skip to content

Commit b757c83

Browse files
Issue #22581: Use more "bytes-like object" throughout the docs and comments.
1 parent 6b33519 commit b757c83

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
@@ -1118,15 +1118,16 @@ to sockets.
11181118
Send normal and ancillary data to the socket, gathering the
11191119
non-ancillary data from a series of buffers and concatenating it
11201120
into a single message. The *buffers* argument specifies the
1121-
non-ancillary data as an iterable of buffer-compatible objects
1121+
non-ancillary data as an iterable of
1122+
:term:`bytes-like objects <bytes-like object>`
11221123
(e.g. :class:`bytes` objects); the operating system may set a limit
11231124
(:func:`~os.sysconf` value ``SC_IOV_MAX``) on the number of buffers
11241125
that can be used. The *ancdata* argument specifies the ancillary
11251126
data (control messages) as an iterable of zero or more tuples
11261127
``(cmsg_level, cmsg_type, cmsg_data)``, where *cmsg_level* and
11271128
*cmsg_type* are integers specifying the protocol level and
11281129
protocol-specific type respectively, and *cmsg_data* is a
1129-
buffer-compatible object holding the associated data. Note that
1130+
bytes-like object holding the associated data. Note that
11301131
some systems (in particular, systems without :func:`CMSG_SPACE`)
11311132
might support sending only one control message per call. The
11321133
*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
@@ -1072,7 +1072,7 @@ to speed up repeated connections from the same clients.
10721072
<http://www.openssl.org/docs/ssl/SSL_CTX_load_verify_locations.html>`_.
10731073

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

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
@@ -1441,14 +1441,14 @@ frombytes(arrayobject *self, Py_buffer *buffer)
14411441
Py_ssize_t n;
14421442
if (buffer->itemsize != 1) {
14431443
PyBuffer_Release(buffer);
1444-
PyErr_SetString(PyExc_TypeError, "string/buffer of bytes required.");
1444+
PyErr_SetString(PyExc_TypeError, "a bytes-like object is required");
14451445
return NULL;
14461446
}
14471447
n = buffer->len;
14481448
if (n % itemsize != 0) {
14491449
PyBuffer_Release(buffer);
14501450
PyErr_SetString(PyExc_ValueError,
1451-
"string length not a multiple of item size");
1451+
"bytes length not a multiple of item size");
14521452
return NULL;
14531453
}
14541454
n = n / itemsize;

Modules/socketmodule.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3493,7 +3493,7 @@ sock_sendmsg(PySocketSockObject *s, PyObject *args)
34933493
for (; ndatabufs < ndataparts; ndatabufs++) {
34943494
if (!PyArg_Parse(PySequence_Fast_GET_ITEM(data_fast, ndatabufs),
34953495
"y*;sendmsg() argument 1 must be an iterable of "
3496-
"buffer-compatible objects",
3496+
"bytes-like objects",
34973497
&databufs[ndatabufs]))
34983498
goto finally;
34993499
iovs[ndatabufs].iov_base = databufs[ndatabufs].buf;
@@ -3650,12 +3650,12 @@ PyDoc_STRVAR(sendmsg_doc,
36503650
Send normal and ancillary data to the socket, gathering the\n\
36513651
non-ancillary data from a series of buffers and concatenating it into\n\
36523652
a single message. The buffers argument specifies the non-ancillary\n\
3653-
data as an iterable of buffer-compatible objects (e.g. bytes objects).\n\
3653+
data as an iterable of bytes-like objects (e.g. bytes objects).\n\
36543654
The ancdata argument specifies the ancillary data (control messages)\n\
36553655
as an iterable of zero or more tuples (cmsg_level, cmsg_type,\n\
36563656
cmsg_data), where cmsg_level and cmsg_type are integers specifying the\n\
36573657
protocol level and protocol-specific type respectively, and cmsg_data\n\
3658-
is a buffer-compatible object holding the associated data. The flags\n\
3658+
is a bytes-like object holding the associated data. The flags\n\
36593659
argument defaults to 0 and has the same meaning as for send(). If\n\
36603660
address is supplied and not None, it sets a destination address for\n\
36613661
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
@@ -2940,8 +2940,7 @@ PyUnicode_FromEncodedObject(PyObject *obj,
29402940
/* Retrieve a bytes buffer view through the PEP 3118 buffer interface */
29412941
if (PyObject_GetBuffer(obj, &buffer, PyBUF_SIMPLE) < 0) {
29422942
PyErr_Format(PyExc_TypeError,
2943-
"coercing to str: need bytes, bytearray "
2944-
"or buffer-like object, %.80s found",
2943+
"coercing to str: need a bytes-like object, %.80s found",
29452944
Py_TYPE(obj)->tp_name);
29462945
return NULL;
29472946
}

0 commit comments

Comments
 (0)