https://github.com/python/cpython/commit/2c1fdf3592cee02f7d2e2f250f2fbd67ddea0a2c
commit: 2c1fdf3592cee02f7d2e2f250f2fbd67ddea0a2c
branch: main
author: Cody Maloney <[email protected]>
committer: kumaraditya303 <[email protected]>
date: 2025-11-26T21:14:25+05:30
summary:

gh-141968: Use `bytearray.take_bytes` in `base64` `_b32encode` and `_b32decode` 
(#141971)

files:
A Misc/NEWS.d/next/Library/2025-11-25-22-54-07.gh-issue-141968.vg3AMJ.rst
M Lib/base64.py

diff --git a/Lib/base64.py b/Lib/base64.py
index f95132a4274051..341bf8eaf1891e 100644
--- a/Lib/base64.py
+++ b/Lib/base64.py
@@ -193,7 +193,7 @@ def _b32encode(alphabet, s):
         encoded[-3:] = b'==='
     elif leftover == 4:
         encoded[-1:] = b'='
-    return bytes(encoded)
+    return encoded.take_bytes()
 
 def _b32decode(alphabet, s, casefold=False, map01=None):
     # Delay the initialization of the table to not waste memory
@@ -238,7 +238,7 @@ def _b32decode(alphabet, s, casefold=False, map01=None):
         last = acc.to_bytes(5)  # big endian
         leftover = (43 - 5 * padchars) // 8  # 1: 4, 3: 3, 4: 2, 6: 1
         decoded[-5:] = last[:leftover]
-    return bytes(decoded)
+    return decoded.take_bytes()
 
 
 def b32encode(s):
diff --git 
a/Misc/NEWS.d/next/Library/2025-11-25-22-54-07.gh-issue-141968.vg3AMJ.rst 
b/Misc/NEWS.d/next/Library/2025-11-25-22-54-07.gh-issue-141968.vg3AMJ.rst
new file mode 100644
index 00000000000000..8492cb35d5bc76
--- /dev/null
+++ b/Misc/NEWS.d/next/Library/2025-11-25-22-54-07.gh-issue-141968.vg3AMJ.rst
@@ -0,0 +1,2 @@
+Remove a data copy from :func:`base64.b32decode` and
+:func:`base64.b32encode` 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]

Reply via email to