https://github.com/python/cpython/commit/6ba3ea43a032ceedaf917fd0f1952afb238756eb
commit: 6ba3ea43a032ceedaf917fd0f1952afb238756eb
branch: 3.15
author: Miss Islington (bot) <[email protected]>
committer: JelleZijlstra <[email protected]>
date: 2026-05-09T21:47:21Z
summary:
[3.15] gh-139871: Fix 3.15 bytearray.take_bytes example (GH-149520) (#149622)
gh-139871: Fix 3.15 bytearray.take_bytes example (GH-149520)
Currently:
```python
buffer = bytearray(b'abc\ndef')
n = buffer.find(b'\n')
data = bytes(buffer[:n + 1])
del buffer[:n + 1]
assert data == b'abc'
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
assert data == b'abc'
^^^^^^^^^^^^^^
AssertionError
```
Adding in the `\n` makes the two match:
```python
buffer = bytearray(b'abc\ndef')
n = buffer.find(b'\n')
data = bytes(buffer[:n + 1])
del buffer[:n + 1]
assert data == b'abc\n'
assert buffer == bytearray(b'def')
buffer = bytearray(b'abc\ndef')
n = buffer.find(b'\n')
data = buffer.take_bytes(n + 1)
assert data == b'abc\n'
assert buffer == bytearray(b'def')
```
(cherry picked from commit cc5cf14ae0a3665ba9d192cc4152c0a46a9dab2f)
Co-authored-by: Cody Maloney <[email protected]>
files:
M Doc/whatsnew/3.15.rst
diff --git a/Doc/whatsnew/3.15.rst b/Doc/whatsnew/3.15.rst
index 0f7782ba1813d1..fb0755e8ffec5b 100644
--- a/Doc/whatsnew/3.15.rst
+++ b/Doc/whatsnew/3.15.rst
@@ -798,7 +798,7 @@ Other language changes
n = buffer.find(b'\n')
data = bytes(buffer[:n + 1])
del buffer[:n + 1]
- assert data == b'abc'
+ assert data == b'abc\n'
assert buffer == bytearray(b'def')
- .. code:: python
_______________________________________________
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]