Skip to content
Merged
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 33 additions & 0 deletions Doc/c-api/bytes.rst
Original file line number Diff line number Diff line change
Expand Up @@ -228,6 +228,39 @@ called with a non-bytes parameter.
The function is :term:`soft deprecated`,
use the :c:type:`PyBytesWriter` API instead.


.. c:function:: PyObject *PyBytes_Repr(PyObject *bytes, int smartquotes)

Get the string representation of *bytes*. This function is used to
implement :meth:`!bytes.__repr__` in Python.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
Get the string representation of *bytes*. This function is used to
implement :meth:`!bytes.__repr__` in Python.
Get the string representation of *bytes*.
*bytes* must be a bytes object.
This function is used to implement :meth:`!bytes.__repr__` in Python.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same remark as the other PR, this reads as "segfault if this isn't a bytes object".

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In this case, it will lead to undefined behaviour.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yuck! I think we should have a more explicit note then. That definitely surprised me.


If *smartquotes* is true, the representation will use a double-quoted string
instead of single-quoted string when single-quotes are present in *bytes*.
For example, the byte string ``'Python'`` would be represented as
``b"'Python'"`` when *smartquotes* is true, or b'\'Python\'' when it is
false.

On success, this function returns a :term:`strong reference` to a
:class:`str` object containing the representation. On failure, this
returns ``NULL`` with an exception set.


.. c:function:: PyObject *PyBytes_DecodeEscape(const char *s, Py_ssize_t len, const char *errors, Py_ssize_t unicode, const char *recode_encoding)

Unescape a backslash-escaped string *s*. *s* must not be ``NULL``.
*len* must be the size of *s*.

*errors* must be one of ``"strict"``, ``"replace"``, or ``"ignore"``. If
*errors* is ``NULL``, then ``"strict"`` is used by default.

On success, this function returns a :term:`strong reference` to a Python
:class:`bytes` object containing the unescaped string. On failure, this
function returns ``NULL`` with an exception set.

.. versionchanged:: 3.9
*unicode* and *recode_encoding* are now unused.


.. _pybyteswriter:

PyBytesWriter
Expand Down
Loading