]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
[3.14] gh-133970: Make PEP750 types generic (GH-133976) (#134029)
authorMiss Islington (bot) <31488909+miss-islington@users.noreply.github.com>
Thu, 15 May 2025 06:39:39 +0000 (08:39 +0200)
committerGitHub <noreply@github.com>
Thu, 15 May 2025 06:39:39 +0000 (06:39 +0000)
gh-133970: Make PEP750 types generic (GH-133976)
(cherry picked from commit c3a1da5b9397867e6b3169dd17cb33ef2898da4a)

Co-authored-by: sobolevn <mail@sobolevn.me>
Lib/test/test_genericalias.py
Misc/NEWS.d/next/Library/2025-05-13-18-54-56.gh-issue-133970.6G-Oi6.rst [new file with mode: 0644]
Objects/interpolationobject.c
Objects/templateobject.c

index 8d21ded45014ba402596994fce3ff9df3d934e2c..ea0dc241e39475e7ddc5446b3356c1b55bf51763 100644 (file)
@@ -61,6 +61,7 @@ try:
     from tkinter import Event
 except ImportError:
     Event = None
+from string.templatelib import Template, Interpolation
 
 from typing import TypeVar
 T = TypeVar('T')
@@ -139,7 +140,10 @@ class BaseTest(unittest.TestCase):
                      DictReader, DictWriter,
                      array,
                      staticmethod,
-                     classmethod]
+                     classmethod,
+                     Template,
+                     Interpolation,
+                    ]
     if ctypes is not None:
         generic_types.extend((ctypes.Array, ctypes.LibraryLoader, ctypes.py_object))
     if ValueProxy is not None:
diff --git a/Misc/NEWS.d/next/Library/2025-05-13-18-54-56.gh-issue-133970.6G-Oi6.rst b/Misc/NEWS.d/next/Library/2025-05-13-18-54-56.gh-issue-133970.6G-Oi6.rst
new file mode 100644 (file)
index 0000000..ddf456d
--- /dev/null
@@ -0,0 +1,2 @@
+Make :class:`!string.templatelib.Template` and
+:class:`!string.templatelib.Interpolation` generic.
index aaea3b8c0670c92e2198e99ba7cba47580c2b973..a5d407a7b0e2968a728073b2fcbfb759414af1e8 100644 (file)
@@ -137,6 +137,8 @@ interpolation_reduce(PyObject *op, PyObject *Py_UNUSED(dummy))
 static PyMethodDef interpolation_methods[] = {
     {"__reduce__", interpolation_reduce, METH_NOARGS,
         PyDoc_STR("__reduce__() -> (cls, state)")},
+    {"__class_getitem__", Py_GenericAlias,
+        METH_O|METH_CLASS, PyDoc_STR("See PEP 585")},
     {NULL, NULL},
 };
 
index 7d356980b56cbbe65b898534d81266c6f155377b..06cb19e0b6d0562a32663db33ca0530fed41d799 100644 (file)
@@ -444,6 +444,8 @@ template_reduce(PyObject *op, PyObject *Py_UNUSED(dummy))
 
 static PyMethodDef template_methods[] = {
     {"__reduce__", template_reduce, METH_NOARGS, NULL},
+    {"__class_getitem__", Py_GenericAlias,
+        METH_O|METH_CLASS, PyDoc_STR("See PEP 585")},
     {NULL, NULL},
 };