https://github.com/python/cpython/commit/f2a4b1066be66574a147bc353efc91a6dc65753d
commit: f2a4b1066be66574a147bc353efc91a6dc65753d
branch: 3.14
author: Miss Islington (bot) <31488909+miss-isling...@users.noreply.github.com>
committer: sobolevn <m...@sobolevn.me>
date: 2025-05-15T06:39:39Z
summary:

[3.14] gh-133970: Make PEP750 types generic (GH-133976) (#134029)

gh-133970: Make PEP750 types generic (GH-133976)
(cherry picked from commit c3a1da5b9397867e6b3169dd17cb33ef2898da4a)

Co-authored-by: sobolevn <m...@sobolevn.me>

files:
A Misc/NEWS.d/next/Library/2025-05-13-18-54-56.gh-issue-133970.6G-Oi6.rst
M Lib/test/test_genericalias.py
M Objects/interpolationobject.c
M Objects/templateobject.c

diff --git a/Lib/test/test_genericalias.py b/Lib/test/test_genericalias.py
index 8d21ded45014ba..ea0dc241e39475 100644
--- a/Lib/test/test_genericalias.py
+++ b/Lib/test/test_genericalias.py
@@ -61,6 +61,7 @@
     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
index 00000000000000..ddf456d3939056
--- /dev/null
+++ b/Misc/NEWS.d/next/Library/2025-05-13-18-54-56.gh-issue-133970.6G-Oi6.rst
@@ -0,0 +1,2 @@
+Make :class:`!string.templatelib.Template` and
+:class:`!string.templatelib.Interpolation` generic.
diff --git a/Objects/interpolationobject.c b/Objects/interpolationobject.c
index aaea3b8c0670c9..a5d407a7b0e296 100644
--- a/Objects/interpolationobject.c
+++ b/Objects/interpolationobject.c
@@ -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},
 };
 
diff --git a/Objects/templateobject.c b/Objects/templateobject.c
index 7d356980b56cbb..06cb19e0b6d056 100644
--- a/Objects/templateobject.c
+++ b/Objects/templateobject.c
@@ -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},
 };
 

_______________________________________________
Python-checkins mailing list -- python-checkins@python.org
To unsubscribe send an email to python-checkins-le...@python.org
https://mail.python.org/mailman3/lists/python-checkins.python.org/
Member address: arch...@mail-archive.com

Reply via email to