From c4f4c750c3cdbb2784181da089432ac4cc189d09 Mon Sep 17 00:00:00 2001 From: Inada Naoki Date: Sat, 5 Sep 2026 07:51:08 +0000 Subject: [PATCH] gh-141968: Use bytearray.take_bytes() in more I/O paths --- Lib/zipfile/__init__.py | 2 +- Modules/_io/iobase.c | 3 +-- 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/Lib/zipfile/__init__.py b/Lib/zipfile/__init__.py index 0accf324c90e3f..c6bd4f8b6fd374 100644 --- a/Lib/zipfile/__init__.py +++ b/Lib/zipfile/__init__.py @@ -759,7 +759,7 @@ def decrypter(data): c ^= ((k * (k^1)) >> 8) & 0xFF update_keys(c) append(c) - return bytes(result) + return result.take_bytes() return decrypter diff --git a/Modules/_io/iobase.c b/Modules/_io/iobase.c index 1253f124108bdb..3fd6007a7f1aac 100644 --- a/Modules/_io/iobase.c +++ b/Modules/_io/iobase.c @@ -664,8 +664,7 @@ _io__IOBase_readline_impl(PyObject *self, Py_ssize_t limit) break; } - result = PyBytes_FromStringAndSize(PyByteArray_AS_STRING(buffer), - PyByteArray_GET_SIZE(buffer)); + result = PyObject_CallMethodNoArgs(buffer, &_Py_ID(take_bytes)); Py_XDECREF(peek); Py_DECREF(buffer); return result;