Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
doc tweaks
  • Loading branch information
cmaloney committed Feb 5, 2025
commit ddc7b0916e4daa3a4b8f7c72a3044e6e3e4b1128
2 changes: 1 addition & 1 deletion Doc/c-api/bytearray.rst
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ Direct API functions
Resize the internal buffer of *bytearray* to *len*. Failure is a ``-1`` return with an exception set.

.. versionchanged:: next
A negative *len* will now result in a failure.
A negative *len* will now result in an exception being set and -1 returned.


Macros
Expand Down
16 changes: 13 additions & 3 deletions Doc/library/stdtypes.rst
Original file line number Diff line number Diff line change
Expand Up @@ -2843,10 +2843,20 @@ objects.

.. method:: resize(size)

Resize the :class:`bytearray` to contain *size* bytes.
If :class:`bytearray` needs to grow, all new bytes will be set to null bytes.
Resize the :class:`bytearray` to contain *size* bytes. *size* must be
greater than or equal to 0.

This is equivalent to ``self += b'\0' * size``
If the :class:`bytearray` needs to shrink bytes beyond *size* are truncated.

If the :class:`bytearray` needs to grow all new bytes, those beyond *size*,
will be set to null bytes.


This is equivalent to:
>>> if len(self) > size:
>>> del self[size:]
>>> else:
>>> self += b'\0' * (size - len(self))

.. versionadded:: next

Expand Down
Loading