[Python-Dev] PEP 467: last round (?) (original) (raw)

Ethan Furman ethan at stoneleaf.us
Sat Sep 3 11:41:58 EDT 2016


On 09/03/2016 05:08 AM, Martin Panter wrote:

On 1 September 2016 at 19:36, Ethan Furman 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, [...]

This one.

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.

Yes.

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-tXf5diMS5NuAOS5udv-3gw3LTWN9WboJw@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')

Nice!

-- Ethan



More information about the Python-Dev mailing list