https://github.com/python/cpython/commit/d0b18b19fa0ed73ce99e49751604f3e7d409b8ba
commit: d0b18b19fa0ed73ce99e49751604f3e7d409b8ba
branch: main
author: Victor Stinner <[email protected]>
committer: vstinner <[email protected]>
date: 2025-10-10T13:01:06+02:00
summary:
gh-129813: Fix PyBytesWriter tests (#139892)
files:
M Doc/c-api/bytes.rst
M Modules/_testcapi/bytes.c
diff --git a/Doc/c-api/bytes.rst b/Doc/c-api/bytes.rst
index 177ebf6c6b3f45..0a73c4748f4411 100644
--- a/Doc/c-api/bytes.rst
+++ b/Doc/c-api/bytes.rst
@@ -260,7 +260,7 @@ Create, Finish, Discard
writer size to *size*. The caller is responsible to write *size*
bytes using :c:func:`PyBytesWriter_GetData`.
- On error, set an exception and return NULL.
+ On error, set an exception and return ``NULL``.
*size* must be positive or zero.
diff --git a/Modules/_testcapi/bytes.c b/Modules/_testcapi/bytes.c
index 388e65456c3a8b..f12fc7f5f3a2a8 100644
--- a/Modules/_testcapi/bytes.c
+++ b/Modules/_testcapi/bytes.c
@@ -79,11 +79,6 @@ writer_new(PyTypeObject *type, PyObject *args, PyObject
*kwargs)
static int
writer_init(PyObject *self_raw, PyObject *args, PyObject *kwargs)
{
- WriterObject *self = (WriterObject *)self_raw;
- if (self->writer) {
- PyBytesWriter_Discard(self->writer);
- }
-
if (kwargs && PyDict_GET_SIZE(kwargs)) {
PyErr_Format(PyExc_TypeError,
"PyBytesWriter() takes exactly no keyword arguments");
@@ -99,6 +94,10 @@ writer_init(PyObject *self_raw, PyObject *args, PyObject
*kwargs)
return -1;
}
+ WriterObject *self = (WriterObject *)self_raw;
+ if (self->writer) {
+ PyBytesWriter_Discard(self->writer);
+ }
if (use_bytearray) {
self->writer = _PyBytesWriter_CreateByteArray(alloc);
}
_______________________________________________
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]