gh-129813: Fix PyBytesWriter tests (#139892)

This commit is contained in:
Victor Stinner
2025-10-10 13:01:06 +02:00
committed by GitHub
parent 4c119714d5
commit d0b18b19fa
2 changed files with 5 additions and 6 deletions

View File

@@ -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.

View File

@@ -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);
}