]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
gh-141968: use `bytearray.take_bytes` in `encodings.idna` (#141975)
authorCody Maloney <cmaloney@users.noreply.github.com>
Wed, 26 Nov 2025 15:46:25 +0000 (07:46 -0800)
committerGitHub <noreply@github.com>
Wed, 26 Nov 2025 15:46:25 +0000 (21:16 +0530)
Lib/encodings/idna.py
Misc/NEWS.d/next/Library/2025-11-25-23-35-07.gh-issue-141968.b3Gscp.rst [new file with mode: 0644]

index 0c90b4c9fe18fad8e2fa6f0dbb7ae39edb0726a3..d31ee07ab45b76df294ab089429a081b29c57de0 100644 (file)
@@ -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 (file)
index 0000000..32658be
--- /dev/null
@@ -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`.