File tree Expand file tree Collapse file tree 2 files changed +14
-4
lines changed
Expand file tree Collapse file tree 2 files changed +14
-4
lines changed Original file line number Diff line number Diff 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
8282Macros
Original file line number Diff line number Diff 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
You can’t perform that action at this time.
0 commit comments