Skip to content

Commit dc76a4a

Browse files
brianschubertpicnixzZeroIntensity
authored
gh-126012: Add __class_getitem__ to memoryview (#126013)
Co-authored-by: Bénédikt Tran <[email protected]> Co-authored-by: Peter Bierma <[email protected]>
1 parent dad3453 commit dc76a4a

File tree

5 files changed

+11
-1
lines changed

5 files changed

+11
-1
lines changed

Doc/library/stdtypes.rst

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3889,6 +3889,9 @@ copying.
38893889
.. versionchanged:: 3.5
38903890
memoryviews can now be indexed with tuple of integers.
38913891

3892+
.. versionchanged:: next
3893+
memoryview is now a :term:`generic type`.
3894+
38923895
:class:`memoryview` has several methods:
38933896

38943897
.. method:: __eq__(exporter)

Doc/whatsnew/3.14.rst

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -194,6 +194,10 @@ Other language changes
194194
:mod:`copyable <copy>`.
195195
(Contributed by Serhiy Storchaka in :gh:`125767`.)
196196

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

198202
New modules
199203
===========

Lib/test/test_genericalias.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@
100100

101101
class BaseTest(unittest.TestCase):
102102
"""Test basics."""
103-
generic_types = [type, tuple, list, dict, set, frozenset, enumerate,
103+
generic_types = [type, tuple, list, dict, set, frozenset, enumerate, memoryview,
104104
defaultdict, deque,
105105
SequenceMatcher,
106106
dircmp,
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
The :class:`memoryview` type now supports subscription, making it a
2+
:term:`generic type`.

Objects/memoryobject.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3286,6 +3286,7 @@ static PyMethodDef memory_methods[] = {
32863286
MEMORYVIEW__FROM_FLAGS_METHODDEF
32873287
{"__enter__", memory_enter, METH_NOARGS, NULL},
32883288
{"__exit__", memory_exit, METH_VARARGS, memory_exit_doc},
3289+
{"__class_getitem__", Py_GenericAlias, METH_O|METH_CLASS, PyDoc_STR("See PEP 585")},
32893290
{NULL, NULL}
32903291
};
32913292

0 commit comments

Comments
 (0)