Skip to content

Commit cdc4bfb

Browse files
Merge branch 'main' into og_fat_build
2 parents dd5f196 + b1f8938 commit cdc4bfb

File tree

195 files changed

+8912
-3474
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

195 files changed

+8912
-3474
lines changed

.github/CODEOWNERS

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -320,3 +320,9 @@ Lib/test/test__colorize.py @hugovk
320320

321321
# Fuzzing
322322
Modules/_xxtestfuzz/ @ammaraskar
323+
324+
# t-strings
325+
**/*interpolationobject* @lysnikolaou
326+
**/*templateobject* @lysnikolaou
327+
**/*templatelib* @lysnikolaou
328+
**/*tstring* @lysnikolaou

.github/workflows/mypy.yml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,11 @@ on:
88
pull_request:
99
paths:
1010
- ".github/workflows/mypy.yml"
11+
- "Lib/_colorize.py"
1112
- "Lib/_pyrepl/**"
1213
- "Lib/test/libregrtest/**"
14+
- "Lib/tomllib/**"
15+
- "Misc/mypy/**"
1316
- "Tools/build/generate_sbom.py"
1417
- "Tools/cases_generator/**"
1518
- "Tools/clinic/**"
@@ -42,6 +45,7 @@ jobs:
4245
target: [
4346
"Lib/_pyrepl",
4447
"Lib/test/libregrtest",
48+
"Lib/tomllib",
4549
"Tools/build",
4650
"Tools/cases_generator",
4751
"Tools/clinic",

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -143,6 +143,7 @@ Tools/unicode/data/
143143
/profile-clean-stamp
144144
/profile-run-stamp
145145
/profile-bolt-stamp
146+
/profile-gen-stamp
146147
/pybuilddir.txt
147148
/pyconfig.h
148149
/python-config

Doc/c-api/unicode.rst

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,14 @@ Python:
3333

3434
.. c:var:: PyTypeObject PyUnicode_Type
3535
36-
This instance of :c:type:`PyTypeObject` represents the Python Unicode type. It
37-
is exposed to Python code as :py:class:`str`.
36+
This instance of :c:type:`PyTypeObject` represents the Python Unicode type.
37+
It is exposed to Python code as :py:class:`str`.
38+
39+
40+
.. c:var:: PyTypeObject PyUnicodeIter_Type
41+
42+
This instance of :c:type:`PyTypeObject` represents the Python Unicode
43+
iterator type. It is used to iterate over Unicode string objects.
3844

3945

4046
.. c:type:: Py_UCS4

Doc/deprecations/pending-removal-in-future.rst

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,6 @@ although there is currently no date scheduled for their removal.
1313
deprecated.
1414
* The :class:`argparse.FileType` type converter is deprecated.
1515

16-
* :mod:`array`'s ``'u'`` format code (:gh:`57281`)
17-
1816
* :mod:`builtins`:
1917

2018
* ``bool(NotImplemented)``.
@@ -49,6 +47,8 @@ although there is currently no date scheduled for their removal.
4947
:data:`calendar.FEBRUARY`.
5048
(Contributed by Prince Roshan in :gh:`103636`.)
5149

50+
* :mod:`codecs`: use :func:`open` instead of :func:`codecs.open`. (:gh:`133038`)
51+
5252
* :attr:`codeobject.co_lnotab`: use the :meth:`codeobject.co_lines` method
5353
instead.
5454

Doc/library/codecs.rst

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -208,6 +208,10 @@ wider range of codecs when working with binary files:
208208
.. versionchanged:: 3.11
209209
The ``'U'`` mode has been removed.
210210

211+
.. deprecated:: next
212+
213+
:func:`codecs.open` has been superseded by :func:`open`.
214+
211215

212216
.. function:: EncodedFile(file, data_encoding, file_encoding=None, errors='strict')
213217

Doc/library/pdb.rst

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -188,6 +188,21 @@ slightly different way:
188188
.. versionadded:: 3.14
189189
The *commands* argument.
190190

191+
192+
.. awaitablefunction:: set_trace_async(*, header=None, commands=None)
193+
194+
async version of :func:`set_trace`. This function should be used inside an
195+
async function with :keyword:`await`.
196+
197+
.. code-block:: python
198+
199+
async def f():
200+
await pdb.set_trace_async()
201+
202+
:keyword:`await` statements are supported if the debugger is invoked by this function.
203+
204+
.. versionadded:: 3.14
205+
191206
.. function:: post_mortem(t=None)
192207

193208
Enter post-mortem debugging of the given exception or

Doc/library/token.rst

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -131,6 +131,41 @@ The token constants are:
131131

132132
The token string contains the closing quote(s).
133133

134+
.. data:: TSTRING_START
135+
136+
Token value used to indicate the beginning of a template string literal.
137+
138+
.. impl-detail::
139+
140+
The token string includes the prefix and the opening quote(s), but none
141+
of the contents of the literal.
142+
143+
.. versionadded:: next
144+
145+
.. data:: TSTRING_MIDDLE
146+
147+
Token value used for literal text inside a template string literal
148+
including format specifications.
149+
150+
.. impl-detail::
151+
152+
Replacement fields (that is, the non-literal parts of t-strings) use
153+
the same tokens as other expressions, and are delimited by
154+
:data:`LBRACE`, :data:`RBRACE`, :data:`EXCLAMATION` and :data:`COLON`
155+
tokens.
156+
157+
.. versionadded:: next
158+
159+
.. data:: TSTRING_END
160+
161+
Token value used to indicate the end of a template string literal.
162+
163+
.. impl-detail::
164+
165+
The token string contains the closing quote(s).
166+
167+
.. versionadded:: next
168+
134169
.. data:: ENDMARKER
135170

136171
Token value that indicates the end of input.

Doc/whatsnew/3.14.rst

Lines changed: 94 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -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
9293
New 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>&lt;script&gt;alert('evil')&lt;/script&gt;</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

97168
PEP 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

11721248
pickle
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`.)

Grammar/Tokens

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,9 @@ SOFT_KEYWORD
6262
FSTRING_START
6363
FSTRING_MIDDLE
6464
FSTRING_END
65+
TSTRING_START
66+
TSTRING_MIDDLE
67+
TSTRING_END
6568
COMMENT
6669
NL
6770
ERRORTOKEN

0 commit comments

Comments
 (0)