https://github.com/python/cpython/commit/c3a1da5b9397867e6b3169dd17cb33ef2898da4a
commit: c3a1da5b9397867e6b3169dd17cb33ef2898da4a
branch: main
author: sobolevn <m...@sobolevn.me>
committer: sobolevn <m...@sobolevn.me>
date: 2025-05-15T09:11:46+03:00
summary:

gh-133970: Make PEP750 types generic (#133976)

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