Skip to content
Merged
23 changes: 9 additions & 14 deletions peps/pep-0467.rst
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ Discussions-To: https://discuss.python.org/t/42001
Status: Draft
Type: Standards Track
Created: 30-Mar-2014
Python-Version: 3.13
Python-Version: 3.15
Post-History: 30-Mar-2014, 15-Aug-2014, 16-Aug-2014, 07-Jun-2016, 01-Sep-2016,
13-Apr-2021, 03-Nov-2021, 27-Dec-2023

Expand All @@ -21,6 +21,8 @@ This PEP proposes small adjustments to the APIs of the ``bytes`` and
* Add ``getbyte`` byte retrieval method
* Add ``iterbytes`` alternative iterator

The last two (``getbyte`` and ``iterbytes``) will also be added to ``memoryview``.

Rationale
=========

Expand All @@ -41,7 +43,7 @@ painful -- wire format protocols.
This area of programming is characterized by a mixture of binary data and
ASCII compatible segments of text (aka ASCII-encoded text). The addition of
the new constructors, methods, and iterators will aid both in writing new
wire format code, and in porting any remaining Python 2 wire format code.
wire format code, and in updating existing code.

Common use-cases include ``dbf`` and ``pdf`` file formats, ``email``
formats, and ``FTP`` and ``HTTP`` communications, among many others.
Expand Down Expand Up @@ -122,8 +124,8 @@ negative numbers. The documentation of the new methods will refer readers to
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``::
This PEP proposes that ``bytes``, ``bytearray``, and ``memoryview`` gain the
method ``getbyte`` which will always return ``bytes``::

>>> b'abc'.getbyte(0)
b'a'
Expand All @@ -139,9 +141,9 @@ If an index is asked for that doesn't exist, ``IndexError`` is raised::
Addition of optimised iterator methods that produce ``bytes`` objects
---------------------------------------------------------------------

This PEP proposes that ``bytes`` and ``bytearray`` gain an optimised
``iterbytes`` method that produces length 1 ``bytes`` objects rather than
integers::
This PEP proposes that ``bytes``, ``bytearray``, and ``memoryview`` gain an
optimised ``iterbytes`` method that produces length 1 ``bytes`` objects rather
than integers::

for x in data.iterbytes():
# x is a length 1 ``bytes`` object, rather than an integer
Expand Down Expand Up @@ -202,13 +204,6 @@ Developers that use this method frequently will instead have the option to
define their own ``bchr = bytes.fromint`` aliases.


Scope limitation: memoryview
----------------------------

Updating ``memoryview`` with the new item retrieval methods is outside the scope
of this PEP.


References
==========

Expand Down