Skip to content

Commit 5ea05b4

Browse files
generatedunixname1734921407115435meta-codesync[bot]
authored andcommitted
Import CPython 3.14.6+ stable branch (2026-06-12)
Summary: Imported python/cpython `3.14.6+` from upstream rev [`945a1ac`](https://www.github.com/python/cpython/commit/945a1ac7a4104f15103338fb73c293a8f5dba803) (committed 2026-06-12 16:10:27+00:00). # Commit Info - Base: (`3.14.5+`) - [`51e83ca`](https://www.github.com/python/cpython/commit/51e83ca706d04878e0f6f0bf8030e0dd2f7585a6) (commit date: 2026-06-09 22:48:25+00:00) - Imported: (`3.14.6+`) - [`945a1ac`](https://www.github.com/python/cpython/commit/945a1ac7a4104f15103338fb73c293a8f5dba803) (commit date: 2026-06-12 16:10:27+00:00) # Noteworthy file changes - Low-signal files (15 added, 67 removed) (NEWS.d, docs, .github) Complete list of added/removed files: https://www.internalfb.com/intern/everpaste/?color=0&handle=GNR9WiViFcKXxYwDAL1fQ5xadR82br0LAAAz Reviewed By: itamaro Differential Revision: D108483023 fbshipit-source-id: c373ab223b85fba9c4d52008c767c325df79329b
1 parent 988ba6d commit 5ea05b4

139 files changed

Lines changed: 1931 additions & 849 deletions

File tree

Some content is hidden

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

.github/workflows/reusable-san.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -86,12 +86,12 @@ jobs:
8686
run: >-
8787
./python -m test
8888
${{ inputs.sanitizer == 'TSan' && '--tsan' || '' }}
89-
-j4
89+
-j4 -W
9090
- name: Parallel tests
9191
if: >-
9292
inputs.sanitizer == 'TSan'
9393
&& fromJSON(inputs.free-threading)
94-
run: ./python -m test --tsan-parallel --parallel-threads=4 -j4
94+
run: ./python -m test --tsan-parallel --parallel-threads=4 -j4 -W
9595
- name: Display logs
9696
if: always()
9797
run: find "${GITHUB_WORKSPACE}" -name 'san_log.*' | xargs head -n 1000

Doc/c-api/memory.rst

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ memory footprint as a whole. Consequently, under certain circumstances, the
8181
Python memory manager may or may not trigger appropriate actions, like garbage
8282
collection, memory compaction or other preventive procedures. Note that by using
8383
the C library allocator as shown in the previous example, the allocated memory
84-
for the I/O buffer escapes completely the Python memory manager.
84+
for the I/O buffer completely escapes the Python memory manager.
8585

8686
.. seealso::
8787

@@ -161,7 +161,7 @@ zero bytes.
161161
162162
.. c:function:: void* PyMem_RawCalloc(size_t nelem, size_t elsize)
163163
164-
Allocates *nelem* elements each whose size in bytes is *elsize* and returns
164+
Allocates *nelem* elements each of size *elsize* bytes and returns
165165
a pointer of type :c:expr:`void*` to the allocated memory, or ``NULL`` if the
166166
request fails. The memory is initialized to zeros.
167167
@@ -239,7 +239,7 @@ In the GIL-enabled build (default build) the
239239
240240
.. c:function:: void* PyMem_Calloc(size_t nelem, size_t elsize)
241241
242-
Allocates *nelem* elements each whose size in bytes is *elsize* and returns
242+
Allocates *nelem* elements each of size *elsize* bytes and returns
243243
a pointer of type :c:expr:`void*` to the allocated memory, or ``NULL`` if the
244244
request fails. The memory is initialized to zeros.
245245
@@ -372,7 +372,7 @@ The :ref:`default object allocator <default-memory-allocators>` uses the
372372
373373
.. c:function:: void* PyObject_Calloc(size_t nelem, size_t elsize)
374374
375-
Allocates *nelem* elements each whose size in bytes is *elsize* and returns
375+
Allocates *nelem* elements each of size *elsize* bytes and returns
376376
a pointer of type :c:expr:`void*` to the allocated memory, or ``NULL`` if the
377377
request fails. The memory is initialized to zeros.
378378

Doc/c-api/weakref.rst

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -42,8 +42,8 @@ as much as it can.
4242
callable object that receives notification when *ob* is garbage collected; it
4343
should accept a single parameter, which will be the weak reference object
4444
itself. *callback* may also be ``None`` or ``NULL``. If *ob* is not a
45-
weakly referenceable object, or if *callback* is not callable, ``None``, or
46-
``NULL``, this will return ``NULL`` and raise :exc:`TypeError`.
45+
weakly referenceable object, this will raise :exc:`TypeError` and return
46+
``NULL``.
4747
4848
.. seealso::
4949
:c:func:`PyType_SUPPORTS_WEAKREFS` for checking if *ob* is weakly
@@ -58,8 +58,8 @@ as much as it can.
5858
be a callable object that receives notification when *ob* is garbage
5959
collected; it should accept a single parameter, which will be the weak
6060
reference object itself. *callback* may also be ``None`` or ``NULL``. If *ob*
61-
is not a weakly referenceable object, or if *callback* is not callable,
62-
``None``, or ``NULL``, this will return ``NULL`` and raise :exc:`TypeError`.
61+
weakly referenceable object, this will raise :exc:`TypeError` and return
62+
``NULL``.
6363
6464
.. seealso::
6565
:c:func:`PyType_SUPPORTS_WEAKREFS` for checking if *ob* is weakly

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

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -33,16 +33,6 @@ Pending removal in Python 3.15
3333

3434
* ``load_module()`` method: use ``exec_module()`` instead.
3535

36-
* :class:`locale`:
37-
38-
* The :func:`~locale.getdefaultlocale` function
39-
has been deprecated since Python 3.11.
40-
Its removal was originally planned for Python 3.13 (:gh:`90817`),
41-
but has been postponed to Python 3.15.
42-
Use :func:`~locale.getlocale`, :func:`~locale.setlocale`,
43-
and :func:`~locale.getencoding` instead.
44-
(Contributed by Hugo van Kemenade in :gh:`111187`.)
45-
4636
* :mod:`pathlib`:
4737

4838
* :meth:`.PurePath.is_reserved`

Doc/library/asyncio-threading.rst

Lines changed: 154 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,154 @@
1+
.. currentmodule:: asyncio
2+
3+
.. _asyncio-threading:
4+
5+
asyncio and free-threaded Python
6+
================================
7+
8+
asyncio uses an event loop as a scheduler to enable highly efficient
9+
concurrency by switching between tasks to allow non-blocking I/O
10+
operations. This results in better performance for I/O-bound use
11+
cases. It also allows off-loading CPU-bound work to a thread or
12+
process pool, but that is still limited by the :term:`global
13+
interpreter lock` in CPython.
14+
15+
However, in :ref:`free-threaded Python <freethreading-python-howto>`,
16+
the GIL is disabled and Python can run true multi-threaded code. This
17+
means that asyncio can now take advantage of multiple CPU cores without
18+
the limitations imposed by the GIL.
19+
20+
Since Python 3.14, asyncio has first-class support for free-threaded
21+
Python, and the implementation of asyncio is safe to use in a
22+
multi-threaded environment.
23+
24+
A single event loop on one core can handle many connections
25+
concurrently, but the Python code that runs to handle each one still
26+
executes serially. Once requests involve a non-trivial amount of
27+
per-request computation, that handling becomes the bottleneck, and a
28+
single core can no longer keep up. Combining asyncio with threads is
29+
most useful here: by running an event loop per thread, the handling of
30+
different requests can run in parallel across multiple CPU cores. It is
31+
also useful when you need to run blocking or CPU-bound code from an
32+
asyncio application.
33+
34+
35+
.. seealso::
36+
37+
`Scaling asyncio on Free-Threaded Python
38+
<https://labs.quansight.org/blog/scaling-asyncio-on-free-threaded-python>`__,
39+
a blog post by Kumar Aditya which explains the internal changes
40+
that make asyncio safe and efficient under free-threaded Python,
41+
together with benchmarks of the resulting improvements.
42+
43+
44+
Thread safety considerations
45+
----------------------------
46+
47+
While asyncio is designed to be thread-safe in a free-threaded Python
48+
environment, there are still some considerations to keep in mind when
49+
using asyncio with threads:
50+
51+
1. **Event loop**: Each thread should have its own event loop which
52+
should not be shared across threads. This ensures that the event loop
53+
can manage its own tasks and callbacks without interference from
54+
other threads.
55+
56+
2. **Task management**: Tasks and futures created in one thread should
57+
not be awaited or manipulated from another thread.
58+
59+
3. **Thread-safe APIs**: When interacting with asyncio from multiple
60+
threads, it's important to use thread-safe APIs provided by asyncio,
61+
such as :func:`asyncio.run_coroutine_threadsafe` for submitting
62+
coroutines to an event loop from another thread. If you need to
63+
call a callback from a different thread, you can use
64+
:meth:`loop.call_soon_threadsafe` to schedule it safely.
65+
66+
4. **Synchronization**: The synchronization primitives provided by
67+
asyncio (like :class:`asyncio.Lock` and :class:`asyncio.Event`)
68+
are not designed to be used across threads. If you need to
69+
synchronize between threads, you should use the synchronization
70+
primitives from the :mod:`threading` module instead.
71+
72+
73+
Using asyncio with threads
74+
--------------------------
75+
76+
asyncio supports running one event loop per thread, which allows you to
77+
take advantage of multiple CPU cores in a free-threaded Python
78+
environment. Each thread can run its own event loop, and tasks can be
79+
scheduled on those loops independently.
80+
81+
Here's an example of how to use asyncio with threads::
82+
83+
import asyncio
84+
import threading
85+
86+
async def worker(name: str) -> None:
87+
print(f"Worker {name} starting")
88+
await asyncio.sleep(1)
89+
print(f"Worker {name} done")
90+
91+
def run_loop(name: str) -> None:
92+
asyncio.run(worker(name))
93+
94+
threads = [
95+
threading.Thread(target=run_loop, args=(f"T{i}",))
96+
for i in range(4)
97+
]
98+
for t in threads:
99+
t.start()
100+
for t in threads:
101+
t.join()
102+
103+
In this example, each thread creates its own event loop with
104+
:func:`asyncio.run` and runs a coroutine on it. The threads execute
105+
concurrently, and in a free-threaded build they can run on separate
106+
CPU cores in parallel.
107+
108+
109+
Producer/consumer across threads
110+
--------------------------------
111+
112+
When a regular (non-asyncio) thread needs to hand work to an asyncio
113+
event loop running in another thread, use a thread-safe primitive such
114+
as :class:`queue.Queue` rather than :class:`asyncio.Queue`, which is
115+
only safe within a single event loop.::
116+
117+
import asyncio
118+
import queue
119+
import threading
120+
121+
def producer(q: queue.Queue[int]) -> None:
122+
for i in range(5):
123+
print(f"Producing {i}")
124+
q.put(i)
125+
q.shutdown()
126+
127+
async def consumer(q: queue.Queue[int]) -> None:
128+
while True:
129+
try:
130+
item = q.get_nowait()
131+
except queue.Empty:
132+
await asyncio.sleep(0.1)
133+
continue
134+
except queue.ShutDown:
135+
break
136+
print(f"Consumed {item}")
137+
await asyncio.sleep(item)
138+
139+
q: queue.Queue[int] = queue.Queue()
140+
consumer_thread = threading.Thread(
141+
target=lambda: asyncio.run(consumer(q))
142+
)
143+
consumer_thread.start()
144+
producer(q)
145+
consumer_thread.join()
146+
147+
The producer runs on the main thread while the consumer runs inside an
148+
event loop on its own thread, yet they communicate safely through
149+
``queue.Queue``. When the queue is empty the consumer sleeps briefly
150+
and tries again. When the producer is done it calls
151+
:meth:`~queue.Queue.shutdown`, which causes subsequent
152+
:meth:`~queue.Queue.get_nowait` calls to raise :exc:`queue.ShutDown`
153+
so the consumer can exit cleanly.
154+

Doc/library/asyncio.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -128,6 +128,7 @@ for full functionality and the latest features.
128128
asyncio-api-index.rst
129129
asyncio-llapi-index.rst
130130
asyncio-dev.rst
131+
asyncio-threading.rst
131132

132133
.. note::
133134
The source code for asyncio can be found in :source:`Lib/asyncio/`.

Doc/library/curses.ascii.rst

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -133,7 +133,7 @@ C library:
133133

134134
.. function:: isgraph(c)
135135

136-
Checks for ASCII any printable character except space.
136+
Checks for any ASCII printable character except space.
137137

138138

139139
.. function:: islower(c)
@@ -148,7 +148,7 @@ C library:
148148

149149
.. function:: ispunct(c)
150150

151-
Checks for any printable ASCII character which is not a space or an alphanumeric
151+
Checks for any ASCII printable character which is not a space or an alphanumeric
152152
character.
153153

154154

Doc/library/dataclasses.rst

Lines changed: 18 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -103,12 +103,25 @@ Module contents
103103
ignored.
104104

105105
- *eq*: If true (the default), an :meth:`~object.__eq__` method will be
106-
generated. This method compares the class as if it were a tuple
107-
of its fields, in order. Both instances in the comparison must
108-
be of the identical type.
106+
generated.
109107

110-
If the class already defines :meth:`!__eq__`, this parameter is
111-
ignored.
108+
This method compares the class by comparing each field in order. Both
109+
instances in the comparison must be of the identical type.
110+
111+
If the class already defines :meth:`!__eq__`, this parameter is ignored.
112+
113+
.. versionchanged:: 3.13
114+
The generated ``__eq__`` method now compares each field individually
115+
(for example, ``self.a == other.a and self.b == other.b``), rather than
116+
comparing tuples of fields as in previous versions.
117+
118+
This change makes the comparison faster but it may alter results in cases
119+
where attributes compare equal by identity but not by value (such as
120+
``float('nan')``).
121+
122+
In Python 3.12 and earlier, the comparison was performed by creating
123+
tuples of the fields and comparing them (for example,
124+
``(self.a, self.b) == (other.a, other.b)``).
112125

113126
- *order*: If true (the default is ``False``), :meth:`~object.__lt__`,
114127
:meth:`~object.__le__`, :meth:`~object.__gt__`, and :meth:`~object.__ge__` methods will be

Doc/library/functions.rst

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -474,7 +474,7 @@ are always available. They are listed here in alphabetical order.
474474
:noindex:
475475
476476
Create a new dictionary. The :class:`dict` object is the dictionary class.
477-
See :class:`dict` and :ref:`typesmapping` for documentation about this class.
477+
See also :ref:`typesmapping` for documentation about this class.
478478

479479
For other containers see the built-in :class:`list`, :class:`set`, and
480480
:class:`tuple` classes, as well as the :mod:`collections` module.
@@ -852,7 +852,7 @@ are always available. They are listed here in alphabetical order.
852852
:noindex:
853853

854854
Return a new :class:`frozenset` object, optionally with elements taken from
855-
*iterable*. ``frozenset`` is a built-in class. See :class:`frozenset` and
855+
*iterable*. :class:`frozenset` is a built-in class. See also
856856
:ref:`types-set` for documentation about this class.
857857

858858
For other containers see the built-in :class:`set`, :class:`list`,
@@ -1808,7 +1808,7 @@ are always available. They are listed here in alphabetical order.
18081808
:noindex:
18091809

18101810
Return a new :class:`set` object, optionally with elements taken from
1811-
*iterable*. ``set`` is a built-in class. See :class:`set` and
1811+
*iterable*. :class:`set` is a built-in class. See also
18121812
:ref:`types-set` for documentation about this class.
18131813

18141814
For other containers see the built-in :class:`frozenset`, :class:`list`,

Doc/library/locale.rst

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -367,8 +367,6 @@ The :mod:`!locale` module defines the following exception and functions:
367367
determined.
368368
The "C" locale is represented as ``(None, None)``.
369369

370-
.. deprecated-removed:: 3.11 3.15
371-
372370

373371
.. function:: getlocale(category=LC_CTYPE)
374372

0 commit comments

Comments
 (0)