FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

[3.15] gh-139871: Fix 3.15 bytearray.take_bytes example (GH-149520) by miss-islington · Pull Request #149622 · python/cpython · GitHub

/ cpython Public

[3.15] gh-139871: Fix 3.15 bytearray.take_bytes example (GH-149520) - #149622

Merged
JelleZijlstra merged 1 commit into
python:3.15from
miss-islington:backport-cc5cf14-3.15
May 9, 2026
Merged

[3.15] gh-139871: Fix 3.15 bytearray.take_bytes example (GH-149520)#149622
JelleZijlstra merged 1 commit into
python:3.15from
miss-islington:backport-cc5cf14-3.15

Conversation

miss-islington commented May 9, 2026
edited by bedevere-app Bot
Loading

Copy link
Copy Markdown
Contributor

Currently:

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:

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 cc5cf14)

Co-authored-by: Cody Maloney cmaloney@users.noreply.github.com

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 cc5cf14)

Co-authored-by: Cody Maloney <cmaloney@users.noreply.github.com>
miss-islington requested a review from AA-Turner as a code owner May 9, 2026 21:39
bedevere-app Bot added docs Documentation in the Doc dir skip news labels May 9, 2026
github-project-automation Bot moved this to Todo in Docs PRs May 9, 2026
JelleZijlstra enabled auto-merge (squash) May 9, 2026 21:43
JelleZijlstra merged commit 6ba3ea4 into python:3.15 May 9, 2026
38 checks passed
github-project-automation Bot moved this from Todo to Done in Docs PRs May 9, 2026
miss-islington deleted the backport-cc5cf14-3.15 branch May 9, 2026 21:47
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

docs Documentation in the Doc dir skip news

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

3 participants


Back | FazBrowse Home | New Git URL