[Python-Dev] PEP 467: Minor API improvements to bytes, bytearray, and memoryview

Barry Warsaw barry at python.org
Thu Jun 9 22:21:57 EDT 2016

On Jun 07, 2016, at 01:28 PM, Ethan Furman wrote:

>Deprecation of current "zero-initialised sequence" behaviour
>Currently, the ``bytes`` and ``bytearray`` constructors accept an integer
>argument and interpret it as meaning to create a zero-initialised sequence of
>the given size::
>     >>> bytes(3)  
>     b'\x00\x00\x00'
>     >>> bytearray(3)  
>     bytearray(b'\x00\x00\x00')
>This PEP proposes to deprecate that behaviour in Python 3.6, and remove it
>entirely in Python 3.7.
>No other changes are proposed to the existing constructors.

Does it need to be *actually* removed?  That does break existing code for not
a lot of benefit.  Yes, the default constructor is a little wonky, but with
the addition of the new constructors, and the fact that you're not proposing
to eventually change the default constructor, removal seems unnecessary.
Besides, once it's removed, what would `bytes(3)` actually do?  The PEP
doesn't say.

Also, since you're proposing to add `bytes.byte(3)` have you considered also
adding an optional count argument?  E.g. `bytes.byte(3, count=7)` would yield
b'\x03\x03\x03\x03\x03\x03\x03'.  That seems like it could be useful.

-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 819 bytes
Desc: OpenPGP digital signature
URL: <http://mail.python.org/pipermail/python-dev/attachments/20160609/9be84756/attachment.sig>

More information about the Python-Dev mailing list