-
-
Notifications
You must be signed in to change notification settings - Fork 32.1k
gh-129559: Add bytearray.resize()
#129560
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 15 commits
e240327
925fcbd
29c04ad
d15ef67
d199032
18829a2
df779e2
facc91f
d8b9faf
7429cf4
c183116
dd46a85
69bbdc1
ec4aa3d
336299a
1a0e157
cf89ec1
ddc7b09
a49374b
298d052
2f6b0a3
bf00f33
8df7b02
43e46dd
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2841,6 +2841,13 @@ objects. | |
optional *sep* and *bytes_per_sep* parameters to insert separators | ||
between bytes in the hex output. | ||
|
||
.. method:: resize(size) | ||
|
||
Resize the :class:`bytearray` to contain *size* bytes. | ||
gpshead marked this conversation as resolved.
Show resolved
Hide resolved
|
||
If :class:`bytearray` needs to grow, all new bytes will be set to null bytes. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Also describe the "obvious-to-us" behavior of what happens when it shrinks: the data at the end is truncated, the remaining data should be equivalent to a ... and consider if the Python version should also support negative size to mean the same thing it would in a slice notation. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 👍 for the truncation. I don't like negative, because the function operates in absolute buffer size, and requesting a negative buffer size sounds like a bug I'd write and I'd prefer an exception / exit rather than debug the symptom "my buffer shrank". There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. my original equivalent to is wrong, which make it look like a delta, current doc one I'm validating: if len(self) > size:
del self[size:]
else:
self += b'\0' * (size - len(self)) |
||
|
||
.. versionadded:: next | ||
|
||
Since bytearray objects are sequences of integers (akin to a list), for a | ||
bytearray object *b*, ``b[0]`` will be an integer, while ``b[0:1]`` will be | ||
a bytearray object of length 1. (This contrasts with text strings, where | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
Add :meth:`bytearray.resize` method to :class:`bytearray` wrapping | ||
:c:func:`PyByteArray_Resize` so :class:`bytearray` can be efficiently | ||
resized in place. | ||
cmaloney marked this conversation as resolved.
Show resolved
Hide resolved
|
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Uh oh!
There was an error while loading. Please reload this page.