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

Martin Panter vadmium+py at gmail.com
Wed Jun 8 00:00:50 EDT 2016


On 7 June 2016 at 21:56, Nick Coghlan <ncoghlan at gmail.com> wrote:
> On 7 June 2016 at 14:33, Paul Sokolovsky <pmiscml at gmail.com> wrote:
>> Ethan Furman <ethan at stoneleaf.us> 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.
>>
>> Why the desire to break applications of thousands and thousands of
>> people?
>
> Same argument as any deprecation: to make existing and future defects
> easier to find or easier to debug.
>
> That said, this is the main part I was referring to in the other
> thread when I mentioned some of the constructor changes were
> potentially controversial and probably not worth the hassle - it's the
> only one with the potential to break currently working code, while the
> others are just a matter of choosing suitable names.

An argument against deprecating bytearray(n) in particular is that
this is supported in Python 2. I think I have (ab)used this fact to
work around the problem with bytes(n) in Python 2 & 3 compatible code.


More information about the Python-Dev mailing list