https://github.com/python/cpython/commit/cc5cf14ae0a3665ba9d192cc4152c0a46a9dab2f
commit: cc5cf14ae0a3665ba9d192cc4152c0a46a9dab2f
branch: main
author: Cody Maloney <[email protected]>
committer: JelleZijlstra <[email protected]>
date: 2026-05-09T14:39:01-07:00
summary:
gh-139871: Fix 3.15 bytearray.take_bytes example (#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')
```
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]