Skip to content

Commit 604a5a6

Browse files
[3.14] pythongh-141004: Document PyBytes_Repr and PyBytes_DecodeEscape (pythonGH-141407) (pythonGH-141440)
* pythongh-141004: Document `PyBytes_Repr` and `PyBytes_DecodeEscape` (pythonGH-141407) Co-authored-by: Stan Ulbrych <[email protected]> (cherry picked from commit 37e2762)
1 parent df04571 commit 604a5a6

File tree

1 file changed

+35
-0
lines changed

1 file changed

+35
-0
lines changed

Doc/c-api/bytes.rst

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -219,3 +219,38 @@ called with a non-bytes parameter.
219219
reallocation fails, the original bytes object at *\*bytes* is deallocated,
220220
*\*bytes* is set to ``NULL``, :exc:`MemoryError` is set, and ``-1`` is
221221
returned.
222+
223+
224+
.. c:function:: PyObject *PyBytes_Repr(PyObject *bytes, int smartquotes)
225+
226+
Get the string representation of *bytes*. This function is currently used to
227+
implement :meth:`!bytes.__repr__` in Python.
228+
229+
This function does not do type checking; it is undefined behavior to pass
230+
*bytes* as a non-bytes object or ``NULL``.
231+
232+
If *smartquotes* is true, the representation will use a double-quoted string
233+
instead of single-quoted string when single-quotes are present in *bytes*.
234+
For example, the byte string ``'Python'`` would be represented as
235+
``b"'Python'"`` when *smartquotes* is true, or ``b'\'Python\''`` when it is
236+
false.
237+
238+
On success, this function returns a :term:`strong reference` to a
239+
:class:`str` object containing the representation. On failure, this
240+
returns ``NULL`` with an exception set.
241+
242+
243+
.. c:function:: PyObject *PyBytes_DecodeEscape(const char *s, Py_ssize_t len, const char *errors, Py_ssize_t unicode, const char *recode_encoding)
244+
245+
Unescape a backslash-escaped string *s*. *s* must not be ``NULL``.
246+
*len* must be the size of *s*.
247+
248+
*errors* must be one of ``"strict"``, ``"replace"``, or ``"ignore"``. If
249+
*errors* is ``NULL``, then ``"strict"`` is used by default.
250+
251+
On success, this function returns a :term:`strong reference` to a Python
252+
:class:`bytes` object containing the unescaped string. On failure, this
253+
function returns ``NULL`` with an exception set.
254+
255+
.. versionchanged:: 3.9
256+
*unicode* and *recode_encoding* are now unused.

0 commit comments

Comments
 (0)