https://github.com/python/cpython/commit/f95a23cbce6438f9072dd6152c782195138e2071
commit: f95a23cbce6438f9072dd6152c782195138e2071
branch: 3.15
author: Miss Islington (bot) <[email protected]>
committer: methane <[email protected]>
date: 2026-10-28T02:54:29Z
summary:

Doc: fix PyBytesWriter sample code (GH-160756)

(cherry picked from commit d8242407a52fe55520ecd84bd088505291e6992f)

Co-authored-by: Inada Naoki <[email protected]>

files:
M Doc/c-api/bytes.rst

diff --git a/Doc/c-api/bytes.rst b/Doc/c-api/bytes.rst
index 3b995de6eb34f5..e1b79a72d951de 100644
--- a/Doc/c-api/bytes.rst
+++ b/Doc/c-api/bytes.rst
@@ -488,7 +488,7 @@ Variant using a pointer to compute the final size::
 
         char *str = PyBytesWriter_GetData(writer);
         memcpy(str, "abc", 3);
-        str += 1;
+        str += 3;
         return PyBytesWriter_FinishWithPointer(writer, str);
     }
 
@@ -537,7 +537,7 @@ Update ``_PyBytes_Resize()`` code
 
 Example of code using the soft deprecated ``_PyBytes_Resize()`` API::
 
-    void create_string(Py_ssize_t size)
+    PyObject* create_string(Py_ssize_t size)
     {
         PyObject *bytes = PyBytes_FromStringAndSize(NULL, size);
         if (bytes == NULL) {
@@ -555,7 +555,7 @@ Example of code using the soft deprecated 
``_PyBytes_Resize()`` API::
 
 It can now be updated to::
 
-    void create_string(Py_ssize_t size)
+    PyObject* create_string(Py_ssize_t size)
     {
         PyBytesWriter *writer = PyBytesWriter_Create(size);
         if (writer == NULL) {

_______________________________________________
Python-checkins mailing list -- [email protected]
To unsubscribe send an email to [email protected]
https://mail.python.org/mailman3//lists/python-checkins.python.org
Member address: [email protected]

Reply via email to