[Python-Dev] PEP 467: last round (?)
Martin Panter
vadmium+py at gmail.com
Sat Sep 3 08:08:53 EDT 2016
On 1 September 2016 at 19:36, Ethan Furman <ethan at stoneleaf.us> wrote:
> Deprecation of current "zero-initialised sequence" behaviour without removal
> ----------------------------------------------------------------------------
>
> 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, but to leave
> it in place for at least as long as Python 2.7 is supported, possibly
> indefinitely.
Can you clarify what “deprecate” means? Just add a note in the
documentation, or make calls trigger a DeprecationWarning as well?
Having bytearray(n) trigger a DeprecationWarning would be a minor
annoyance for code being compatible with Python 2 and 3, since
bytearray(n) is supported in Python 2.
> Addition of "getbyte" method to retrieve a single byte
> ------------------------------------------------------
>
> This PEP proposes that ``bytes`` and ``bytearray`` gain the method
> ``getbyte``
> which will always return ``bytes``::
Should getbyte() handle negative indexes? E.g. getbyte(-1) returning
the last byte.
> Open Questions
> ==============
>
> Do we add ``iterbytes`` to ``memoryview``, or modify
> ``memoryview.cast()`` to accept ``'s'`` as a single-byte interpretation? Or
> do we ignore memory for now and add it later?
Apparently memoryview.cast('s') comes from Nick Coghlan:
<https://marc.info/?i=CADiSq7e=8ieyeW-tXf5diMS_5NuAOS5udv-3g_w3LTWN9WboJw@mail.gmail.com>.
However, since 3.5 (https://bugs.python.org/issue15944) you can call
cast("c") on most memoryviews, which I think already does what you
want:
>>> tuple(memoryview(b"ABC").cast("c"))
(b'A', b'B', b'C')
More information about the Python-Dev
mailing list