From 2e8b344b100e0339bb826c76bf9d65aa55e3fe2b Mon Sep 17 00:00:00 2001 From: Victor Stinner Date: Tue, 16 Sep 2025 10:11:42 +0200 Subject: [PATCH] gh-129813, PEP 782: Soft deprecate _PyBytes_Resize() Soft deprecate _PyBytes_Resize() and PyBytes_FromStringAndSize(NULL, size). --- Doc/c-api/bytes.rst | 9 +++++++++ Doc/whatsnew/3.15.rst | 5 +++++ 2 files changed, 14 insertions(+) diff --git a/Doc/c-api/bytes.rst b/Doc/c-api/bytes.rst index 8cc935cd06659c..89ff070f1c5cf7 100644 --- a/Doc/c-api/bytes.rst +++ b/Doc/c-api/bytes.rst @@ -47,6 +47,10 @@ called with a non-bytes parameter. *len* on success, and ``NULL`` on failure. If *v* is ``NULL``, the contents of the bytes object are uninitialized. + .. deprecated:: 3.15 + ``PyBytes_FromStringAndSize(NULL, len)`` is :term:`soft deprecated`, + use the :c:type:`PyBytesWriter` API instead. + .. c:function:: PyObject* PyBytes_FromFormat(const char *format, ...) @@ -220,6 +224,11 @@ called with a non-bytes parameter. *\*bytes* is set to ``NULL``, :exc:`MemoryError` is set, and ``-1`` is returned. + .. deprecated:: 3.15 + The function is :term:`soft deprecated`, + use the :c:type:`PyBytesWriter` API instead. + + PyBytesWriter ------------- diff --git a/Doc/whatsnew/3.15.rst b/Doc/whatsnew/3.15.rst index ed44558c1d3beb..0775edc6830f57 100644 --- a/Doc/whatsnew/3.15.rst +++ b/Doc/whatsnew/3.15.rst @@ -774,6 +774,11 @@ Deprecated C APIs signed integer type of the same size is now deprecated. (Contributed by Serhiy Storchaka in :gh:`132629`.) +* :c:func:`PyBytes_FromStringAndSize(NULL, len) ` + and :c:func:`_PyBytes_Resize` are :term:`soft deprecated`, + use the :c:type:`PyBytesWriter` API instead. + (Contributed by Victor Stinner in :gh:`129813`.) + * Deprecate :c:member:`~PyComplexObject.cval` field of the the :c:type:`PyComplexObject` type. Use :c:func:`PyComplex_AsCComplex` and :c:func:`PyComplex_FromCComplex`