From: Cody Maloney Date: Wed, 26 Nov 2025 15:46:25 +0000 (-0800) Subject: gh-141968: use `bytearray.take_bytes` in `encodings.idna` (#141975) X-Git-Tag: v3.15.0a3~267 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=9ac14288d7147dbbae08a8ffd8581e0f5e6fd706;p=thirdparty%2FPython%2Fcpython.git gh-141968: use `bytearray.take_bytes` in `encodings.idna` (#141975) --- diff --git a/Lib/encodings/idna.py b/Lib/encodings/idna.py index 0c90b4c9fe18..d31ee07ab45b 100644 --- a/Lib/encodings/idna.py +++ b/Lib/encodings/idna.py @@ -226,7 +226,8 @@ class Codec(codecs.Codec): offset + exc.end, exc.reason, ) - return bytes(result+trailing_dot), len(input) + result += trailing_dot + return result.take_bytes(), len(input) def decode(self, input, errors='strict'): @@ -311,7 +312,7 @@ class IncrementalEncoder(codecs.BufferedIncrementalEncoder): result += trailing_dot size += len(trailing_dot) - return (bytes(result), size) + return (result.take_bytes(), size) class IncrementalDecoder(codecs.BufferedIncrementalDecoder): def _buffer_decode(self, input, errors, final): diff --git a/Misc/NEWS.d/next/Library/2025-11-25-23-35-07.gh-issue-141968.b3Gscp.rst b/Misc/NEWS.d/next/Library/2025-11-25-23-35-07.gh-issue-141968.b3Gscp.rst new file mode 100644 index 000000000000..32658be5b2f6 --- /dev/null +++ b/Misc/NEWS.d/next/Library/2025-11-25-23-35-07.gh-issue-141968.b3Gscp.rst @@ -0,0 +1,2 @@ +Remove data copy from :mod:`encodings.idna` :meth:`~codecs.Codec.encode` and +:meth:`~codecs.IncrementalEncoder.encode` by using :func:`bytearray.take_bytes`.