Skip to content

gh-126012: Add __class_getitem__ to memoryview #126013

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

Merged
merged 5 commits into from
Oct 27, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions Doc/library/stdtypes.rst
Original file line number Diff line number Diff line change
Expand Up @@ -3889,6 +3889,9 @@ copying.
.. versionchanged:: 3.5
memoryviews can now be indexed with tuple of integers.

.. versionchanged:: next
memoryview is now a :term:`generic type`.

:class:`memoryview` has several methods:

.. method:: __eq__(exporter)
Expand Down
4 changes: 4 additions & 0 deletions Doc/whatsnew/3.14.rst
Original file line number Diff line number Diff line change
Expand Up @@ -194,6 +194,10 @@ Other language changes
:mod:`copyable <copy>`.
(Contributed by Serhiy Storchaka in :gh:`125767`.)

* The :class:`memoryview` type now supports subscription,
making it a :term:`generic type`.
(Contributed by Brian Schubert in :gh:`126012`.)


New modules
===========
Expand Down
2 changes: 1 addition & 1 deletion Lib/test/test_genericalias.py
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@

class BaseTest(unittest.TestCase):
"""Test basics."""
generic_types = [type, tuple, list, dict, set, frozenset, enumerate,
generic_types = [type, tuple, list, dict, set, frozenset, enumerate, memoryview,
defaultdict, deque,
SequenceMatcher,
dircmp,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
The :class:`memoryview` type now supports subscription, making it a
:term:`generic type`.
1 change: 1 addition & 0 deletions Objects/memoryobject.c
Original file line number Diff line number Diff line change
Expand Up @@ -3286,6 +3286,7 @@ static PyMethodDef memory_methods[] = {
MEMORYVIEW__FROM_FLAGS_METHODDEF
{"__enter__", memory_enter, METH_NOARGS, NULL},
{"__exit__", memory_exit, METH_VARARGS, memory_exit_doc},
{"__class_getitem__", Py_GenericAlias, METH_O|METH_CLASS, PyDoc_STR("See PEP 585")},
{NULL, NULL}
};

Expand Down
Loading