Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Pep 467: include memoryview, drop 2->3 conversion text #3660

Open
wants to merge 10 commits into
base: main
Choose a base branch
from
21 changes: 8 additions & 13 deletions peps/pep-0467.rst
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,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 @@ -44,7 +46,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 @@ -125,8 +127,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 @@ -142,9 +144,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 @@ -205,13 +207,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
Loading