From 29a5566eff1505044d03b4863ef7cc223b7d1e5e Mon Sep 17 00:00:00 2001 From: Ethan Smith Date: Tue, 7 Apr 2020 15:44:01 -0700 Subject: [PATCH] Make enumerate, AsyncGeneratorType, mmap generic --- Lib/test/test_genericalias.py | 9 ++++++--- Modules/mmapmodule.c | 2 ++ Objects/enumobject.c | 2 ++ Objects/genobject.c | 2 ++ 4 files changed, 12 insertions(+), 3 deletions(-) diff --git a/Lib/test/test_genericalias.py b/Lib/test/test_genericalias.py index 9c5b23e5e5b0fc..0c6699b840467c 100644 --- a/Lib/test/test_genericalias.py +++ b/Lib/test/test_genericalias.py @@ -7,9 +7,10 @@ ) from collections.abc import * from contextlib import AbstractContextManager, AbstractAsyncContextManager +from mmap import mmap from os import DirEntry from re import Pattern, Match -from types import GenericAlias, MappingProxyType +from types import GenericAlias, MappingProxyType, AsyncGeneratorType import typing from typing import TypeVar @@ -19,7 +20,8 @@ class BaseTest(unittest.TestCase): """Test basics.""" def test_subscriptable(self): - for t in (type, tuple, list, dict, set, frozenset, + for t in (type, tuple, list, dict, set, frozenset, enumerate, + mmap, defaultdict, deque, OrderedDict, Counter, UserDict, UserList, Pattern, Match, @@ -35,7 +37,8 @@ def test_subscriptable(self): Mapping, MutableMapping, MappingView, KeysView, ItemsView, ValuesView, Sequence, MutableSequence, - MappingProxyType, DirEntry + MappingProxyType, AsyncGeneratorType, + DirEntry ): tname = t.__name__ with self.subTest(f"Testing {tname}"): diff --git a/Modules/mmapmodule.c b/Modules/mmapmodule.c index a5c0ae0eaf065a..a1267bdd549c14 100644 --- a/Modules/mmapmodule.c +++ b/Modules/mmapmodule.c @@ -816,6 +816,8 @@ static struct PyMethodDef mmap_object_methods[] = { #ifdef MS_WINDOWS {"__sizeof__", (PyCFunction) mmap__sizeof__method, METH_NOARGS}, #endif + {"__class_getitem__", (PyCFunction)Py_GenericAlias, METH_O|METH_CLASS, + PyDoc_STR("See PEP 585")}, {NULL, NULL} /* sentinel */ }; diff --git a/Objects/enumobject.c b/Objects/enumobject.c index 75703be5fcfc54..4a83bb45aa6678 100644 --- a/Objects/enumobject.c +++ b/Objects/enumobject.c @@ -201,6 +201,8 @@ PyDoc_STRVAR(reduce_doc, "Return state information for pickling."); static PyMethodDef enum_methods[] = { {"__reduce__", (PyCFunction)enum_reduce, METH_NOARGS, reduce_doc}, + {"__class_getitem__", (PyCFunction)Py_GenericAlias, + METH_O|METH_CLASS, PyDoc_STR("See PEP 585")}, {NULL, NULL} /* sentinel */ }; diff --git a/Objects/genobject.c b/Objects/genobject.c index 6bb08aeaff76b4..d3455f8dcd7923 100644 --- a/Objects/genobject.c +++ b/Objects/genobject.c @@ -1346,6 +1346,8 @@ static PyMethodDef async_gen_methods[] = { {"asend", (PyCFunction)async_gen_asend, METH_O, async_asend_doc}, {"athrow",(PyCFunction)async_gen_athrow, METH_VARARGS, async_athrow_doc}, {"aclose", (PyCFunction)async_gen_aclose, METH_NOARGS, async_aclose_doc}, + {"__class_getitem__", (PyCFunction)Py_GenericAlias, + METH_O|METH_CLASS, PyDoc_STR("See PEP 585")}, {NULL, NULL} /* Sentinel */ };