mirror of
https://github.com/python/cpython.git
synced 2025-08-01 23:53:15 +00:00
make bytes(o) respect __bytes__ #2415
This adds two new C-API functions: PyObject_Bytes and PyBytes_FromObject. Reviewer: Barry
This commit is contained in:
parent
a786b026c9
commit
c15a07333e
8 changed files with 83 additions and 2 deletions
|
@ -118,6 +118,12 @@ called with a non-bytes parameter.
|
|||
arguments.
|
||||
|
||||
|
||||
.. cfunction:: PyObject* PyBytes_FromObject(PyObject *o)
|
||||
|
||||
Return the bytes representation of object *o* that implements the buffer
|
||||
protocol.
|
||||
|
||||
|
||||
.. cfunction:: Py_ssize_t PyBytes_Size(PyObject *o)
|
||||
|
||||
Return the length of the bytes in bytes object *o*.
|
||||
|
|
|
@ -139,6 +139,14 @@ Object Protocol
|
|||
Python expression ``str(o)``. Called by the :func:`str` built-in function
|
||||
and, therefore, by the :func:`print` function.
|
||||
|
||||
.. cfunction:: PyObject* PyObject_Bytes(PyObject *o)
|
||||
|
||||
.. index:: builtin: bytes
|
||||
|
||||
Compute a bytes representation of object *o*. *NULL* is returned on failure
|
||||
and a bytes object on success. This is equivalent to the Python expression
|
||||
``bytes(o)``.
|
||||
|
||||
|
||||
.. cfunction:: int PyObject_IsInstance(PyObject *inst, PyObject *cls)
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue