Skip to content

Commit ddc7b09

Browse files
committed
doc tweaks
1 parent cf89ec1 commit ddc7b09

File tree

2 files changed

+14
-4
lines changed

2 files changed

+14
-4
lines changed

Doc/c-api/bytearray.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ Direct API functions
7676
Resize the internal buffer of *bytearray* to *len*. Failure is a ``-1`` return with an exception set.
7777
7878
.. versionchanged:: next
79-
A negative *len* will now result in a failure.
79+
A negative *len* will now result in an exception being set and -1 returned.
8080
8181
8282
Macros

Doc/library/stdtypes.rst

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2843,10 +2843,20 @@ objects.
28432843

28442844
.. method:: resize(size)
28452845

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

2849-
This is equivalent to ``self += b'\0' * size``
2849+
If the :class:`bytearray` needs to shrink bytes beyond *size* are truncated.
2850+
2851+
If the :class:`bytearray` needs to grow all new bytes, those beyond *size*,
2852+
will be set to null bytes.
2853+
2854+
2855+
This is equivalent to:
2856+
>>> if len(self) > size:
2857+
>>> del self[size:]
2858+
>>> else:
2859+
>>> self += b'\0' * (size - len(self))
28502860

28512861
.. versionadded:: next
28522862

0 commit comments

Comments
 (0)