add discouraged use example

This commit is contained in:
Ethan Furman 2023-12-28 11:37:25 -08:00
parent 9f5ceed90a
commit 68f8127d26
1 changed files with 6 additions and 4 deletions

View File

@ -56,10 +56,12 @@ Proposals
Addition of explicit "count and byte initialised sequence" constructors
-----------------------------------------------------------------------
To replace the now discouraged behavior, this PEP proposes the addition of an
explicit ``fromsize`` alternative constructor as a class method on both
``bytes`` and ``bytearray`` whose first argument is the count, and whose
second argument is the fill byte to use (defaults to ``\x00``)::
To replace the discouraged behavior of creating zero-filled ``bytes``-like
objects from the basic constructors (i.e. ``bytes(1)`` --> ``b'\x00'``), this
PEP proposes the addition of an explicit ``fromsize`` alternative constructor
as a class method on both ``bytes`` and ``bytearray`` whose first argument
is the count, and whose second argument is the fill byte to use (defaults
to ``\x00``)::
>>> bytes.fromsize(3)
b'\x00\x00\x00'