PEP 467: add discouraged use example (#3611)
Co-authored-by: Hugo van Kemenade <hugovk@users.noreply.github.com>
This commit is contained in:
parent
641c75fac9
commit
3728f0d47a
|
@ -16,7 +16,7 @@ Post-History: 30-Mar-2014, 15-Aug-2014, 16-Aug-2014, 07-Jun-2016, 01-Sep-2016,
|
||||||
Abstract
|
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:
|
``bytearray`` types to make it easier to operate entirely in the binary domain:
|
||||||
|
|
||||||
* Add ``fromsize`` alternative constructor
|
* Add ``fromsize`` alternative constructor
|
||||||
|
@ -56,10 +56,12 @@ Proposals
|
||||||
Addition of explicit "count and byte initialised sequence" constructors
|
Addition of explicit "count and byte initialised sequence" constructors
|
||||||
-----------------------------------------------------------------------
|
-----------------------------------------------------------------------
|
||||||
|
|
||||||
To replace the now discouraged behavior, this PEP proposes the addition of an
|
To replace the discouraged behavior of creating zero-filled ``bytes``-like
|
||||||
explicit ``fromsize`` alternative constructor as a class method on both
|
objects from the basic constructors (i.e. ``bytes(1)`` --> ``b'\x00'``), this
|
||||||
``bytes`` and ``bytearray`` whose first argument is the count, and whose
|
PEP proposes the addition of an explicit ``fromsize`` alternative constructor
|
||||||
second argument is the fill byte to use (defaults to ``\x00``)::
|
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)
|
>>> bytes.fromsize(3)
|
||||||
b'\x00\x00\x00'
|
b'\x00\x00\x00'
|
||||||
|
|
Loading…
Reference in New Issue