diff options
author | Guido van Rossum <guido@python.org> | 2020-04-07 16:50:06 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-04-07 16:50:06 (GMT) |
commit | 48b069a003ba6c684a9ba78493fbbec5e89f10b8 (patch) | |
tree | e67e71abd17516cea5fe1a1ec487bf929ab0b9fd /Modules | |
parent | 9cc3ebd7e04cb645ac7b2f372eaafa7464e16b9c (diff) | |
download | cpython-48b069a003ba6c684a9ba78493fbbec5e89f10b8.zip cpython-48b069a003ba6c684a9ba78493fbbec5e89f10b8.tar.gz cpython-48b069a003ba6c684a9ba78493fbbec5e89f10b8.tar.bz2 |
bpo-39481: Implementation for PEP 585 (#18239)
This implements things like `list[int]`,
which returns an object of type `types.GenericAlias`.
This object mostly acts as a proxy for `list`,
but has attributes `__origin__` and `__args__`
that allow recovering the parts (with values `list` and `(int,)`.
There is also an approximate notion of type variables;
e.g. `list[T]` has a `__parameters__` attribute equal to `(T,)`.
Type variables are objects of type `typing.TypeVar`.
Diffstat (limited to 'Modules')
-rw-r--r-- | Modules/_collectionsmodule.c | 4 | ||||
-rw-r--r-- | Modules/_sre.c | 4 |
2 files changed, 8 insertions, 0 deletions
diff --git a/Modules/_collectionsmodule.c b/Modules/_collectionsmodule.c index 11342a3..181e322 100644 --- a/Modules/_collectionsmodule.c +++ b/Modules/_collectionsmodule.c @@ -1609,6 +1609,8 @@ static PyMethodDef deque_methods[] = { METH_FASTCALL, rotate_doc}, {"__sizeof__", (PyCFunction)deque_sizeof, METH_NOARGS, sizeof_doc}, + {"__class_getitem__", (PyCFunction)Py_GenericAlias, + METH_O|METH_CLASS, PyDoc_STR("See PEP 585")}, {NULL, NULL} /* sentinel */ }; @@ -2074,6 +2076,8 @@ static PyMethodDef defdict_methods[] = { defdict_copy_doc}, {"__reduce__", (PyCFunction)defdict_reduce, METH_NOARGS, reduce_doc}, + {"__class_getitem__", (PyCFunction)Py_GenericAlias, METH_O|METH_CLASS, + PyDoc_STR("See PEP 585")}, {NULL} }; diff --git a/Modules/_sre.c b/Modules/_sre.c index 15950c6..52ed420 100644 --- a/Modules/_sre.c +++ b/Modules/_sre.c @@ -2568,6 +2568,8 @@ static PyMethodDef pattern_methods[] = { _SRE_SRE_PATTERN_SCANNER_METHODDEF _SRE_SRE_PATTERN___COPY___METHODDEF _SRE_SRE_PATTERN___DEEPCOPY___METHODDEF + {"__class_getitem__", (PyCFunction)Py_GenericAlias, METH_O|METH_CLASS, + PyDoc_STR("See PEP 585")}, {NULL, NULL} }; @@ -2638,6 +2640,8 @@ static PyMethodDef match_methods[] = { _SRE_SRE_MATCH_EXPAND_METHODDEF _SRE_SRE_MATCH___COPY___METHODDEF _SRE_SRE_MATCH___DEEPCOPY___METHODDEF + {"__class_getitem__", (PyCFunction)Py_GenericAlias, METH_O|METH_CLASS, + PyDoc_STR("See PEP 585")}, {NULL, NULL} }; |