@@ -66,6 +66,7 @@ Summary -- release highlights
6666
6767 * :ref: `PEP 649: deferred evaluation of annotations <whatsnew314-pep649 >`
6868* :ref: `PEP 741: Python Configuration C API <whatsnew314-pep741 >`
69+ * :ref: `PEP 750: Template Strings <whatsnew314-pep750 >`
6970* :ref: `PEP 758: Allow except and except* expressions without parentheses <whatsnew314-pep758 >`
7071* :ref: `PEP 761: Discontinuation of PGP signatures <whatsnew314-pep761 >`
7172* :ref: `PEP 765: Disallow return/break/continue that exit a finally block <whatsnew314-pep765 >`
@@ -92,6 +93,76 @@ If you encounter :exc:`NameError`\s or pickling errors coming out of
9293New features
9394============
9495
96+ .. _whatsnew314-pep750 :
97+
98+ PEP 750: Template Strings
99+ -------------------------
100+
101+ Template string literals (t-strings) are a generalization of f-strings,
102+ using a ``t `` in place of the ``f `` prefix. Instead of evaluating
103+ to :class: `str `, t-strings evaluate to a new :class: `!string.templatelib.Template ` type:
104+
105+ .. code-block :: python
106+
107+ from string.templatelib import Template
108+
109+ name = " World"
110+ template: Template = t" Hello {name} "
111+
112+ The template can then be combined with functions that operate on the template's
113+ structure to produce a :class: `str ` or a string-like result.
114+ For example, sanitizing input:
115+
116+ .. code-block :: python
117+
118+ evil = " <script>alert('evil')</script>"
119+ template = t" <p>{evil} </p>"
120+ assert html(template) == " <p><script>alert('evil')</script></p>"
121+
122+ As another example, generating HTML attributes from data:
123+
124+ .. code-block :: python
125+
126+ attributes = {" src" : " shrubbery.jpg" , " alt" : " looks nice" }
127+ template = t" <img {attributes} />"
128+ assert html(template) == ' <img src="shrubbery.jpg" alt="looks nice" class="looks-nice" />'
129+
130+ Unlike f-strings, the ``html `` function has access to template attributes
131+ containing the original information: static strings, interpolations, and values
132+ from the original scope. Unlike existing templating approaches, t-strings build
133+ from the well-known f-string syntax and rules. Template systems thus benefit
134+ from Python tooling as they are much closer to the Python language, syntax,
135+ scoping, and more.
136+
137+ Writing template handlers is straightforward:
138+
139+ .. code-block :: python
140+
141+ from string.templatelib import Template, Interpolation
142+
143+ def lower_upper (template : Template) -> str :
144+ """ Render static parts lowercased and interpolations uppercased."""
145+ parts: list[str ] = []
146+ for item in template:
147+ if isinstance (item, Interpolation):
148+ parts.append(str (item.value).upper())
149+ else :
150+ parts.append(item.lower())
151+ return " " .join(parts)
152+
153+ name = " world"
154+ assert lower_upper(t" HELLO {name} " ) == " hello WORLD"
155+
156+ With this in place, developers can write template systems to sanitize SQL, make
157+ safe shell operations, improve logging, tackle modern ideas in web development
158+ (HTML, CSS, and so on), and implement lightweight, custom business DSLs.
159+
160+ See :pep: `750 ` for more details.
161+
162+ (Contributed by Jim Baker, Guido van Rossum, Paul Everitt, Koudai Aono,
163+ Lysandros Nikolaou, Dave Peck, Adam Turner, Jelle Zijlstra, Bénédikt Tran,
164+ and Pablo Galindo Salgado in :gh: `132661 `.)
165+
95166.. _whatsnew314-pep768 :
96167
97168PEP 768: Safe external debugger interface for CPython
@@ -1168,6 +1239,11 @@ pdb
11681239 backend by default, which is configurable.
11691240 (Contributed by Tian Gao in :gh: `124533 `.)
11701241
1242+ * :func: `pdb.set_trace_async ` is added to support debugging asyncio
1243+ coroutines. :keyword: `await ` statements are supported with this
1244+ function.
1245+ (Contributed by Tian Gao in :gh: `132576 `.)
1246+
11711247
11721248pickle
11731249------
@@ -1592,6 +1668,10 @@ Deprecated
15921668 as a single positional argument.
15931669 (Contributed by Serhiy Storchaka in :gh: `109218 `.)
15941670
1671+ * :mod: `codecs `:
1672+ :func: `codecs.open ` is now deprecated. Use :func: `open ` instead.
1673+ (Contributed by Inada Naoki in :gh: `133036 `.)
1674+
15951675* :mod: `functools `:
15961676 Calling the Python implementation of :func: `functools.reduce ` with *function *
15971677 or *sequence * as keyword arguments is now deprecated.
@@ -1637,6 +1717,13 @@ Deprecated
16371717 Deprecate :meth: `symtable.Class.get_methods ` due to the lack of interest.
16381718 (Contributed by Bénédikt Tran in :gh: `119698 `.)
16391719
1720+ * :mod: `tkinter `:
1721+ The :class: `!tkinter.Variable ` methods :meth: `!trace_variable `,
1722+ :meth: `!trace_vdelete ` and :meth: `!trace_vinfo ` are now deprecated.
1723+ Use :meth: `!trace_add `, :meth: `!trace_remove ` and :meth: `!trace_info `
1724+ instead.
1725+ (Contributed by Serhiy Storchaka in :gh: `120220 `.)
1726+
16401727* :mod: `urllib.parse `:
16411728 Accepting objects with false values (like ``0 `` and ``[] ``) except empty
16421729 strings, byte-like objects and ``None `` in :mod: `urllib.parse ` functions
@@ -2280,3 +2367,10 @@ Removed
22802367* Remove the private ``_Py_InitializeMain() `` function. It was a
22812368 :term: `provisional API ` added to Python 3.8 by :pep: `587 `.
22822369 (Contributed by Victor Stinner in :gh: `129033 `.)
2370+
2371+ * The undocumented APIs :c:macro: `!Py_C_RECURSION_LIMIT ` and
2372+ :c:member: `!PyThreadState.c_recursion_remaining `, added in 3.13, are removed
2373+ without a deprecation period.
2374+ Please use :c:func: `Py_EnterRecursiveCall ` to guard against runaway recursion
2375+ in C code.
2376+ (Removed in :gh: `133079 `, see also :gh: `130396 `.)
0 commit comments