https://github.com/python/cpython/commit/9ac14288d7147dbbae08a8ffd8581e0f5e6fd706
commit: 9ac14288d7147dbbae08a8ffd8581e0f5e6fd706
branch: main
author: Cody Maloney <[email protected]>
committer: kumaraditya303 <[email protected]>
date: 2025-11-26T21:16:25+05:30
summary:
gh-141968: use `bytearray.take_bytes` in `encodings.idna` (#141975)
files:
A Misc/NEWS.d/next/Library/2025-11-25-23-35-07.gh-issue-141968.b3Gscp.rst
M Lib/encodings/idna.py
diff --git a/Lib/encodings/idna.py b/Lib/encodings/idna.py
index 0c90b4c9fe18fa..d31ee07ab45b76 100644
--- a/Lib/encodings/idna.py
+++ b/Lib/encodings/idna.py
@@ -226,7 +226,8 @@ def encode(self, input, errors='strict'):
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 @@ def _buffer_encode(self, input, errors, final):
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 00000000000000..32658be5b2f632
--- /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`.
_______________________________________________
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]