PEP 467: add discouraged use example (#3611)

Co-authored-by: Hugo van Kemenade <hugovk@users.noreply.github.com>
This commit is contained in:
Ethan Furman 2024-02-07 05:44:54 -08:00 committed by GitHub
parent 641c75fac9
commit 3728f0d47a
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
1 changed files with 7 additions and 5 deletions

View File

@ -16,7 +16,7 @@ Post-History: 30-Mar-2014, 15-Aug-2014, 16-Aug-2014, 07-Jun-2016, 01-Sep-2016,
Abstract
========
This PEP proposes five small adjustments to the APIs of the ``bytes`` and
This PEP proposes small adjustments to the APIs of the ``bytes`` and
``bytearray`` types to make it easier to operate entirely in the binary domain:
* Add ``fromsize`` alternative constructor
@ -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'