Skip to content

Commit 1e45fd2

Browse files
generatedunixname1734921407115435meta-codesync[bot]
authored andcommitted
Sync pre-release CPython main branch from GitHub (2026-08-01)
Summary: Imported python/cpython `3.16.0a0` from upstream rev [`7b4165b`](https://www.github.com/python/cpython/commit/7b4165b3b07638d8aeab79a880c52f2b51c56f37) (committed 2026-08-01 19:54:04+00:00). # Commit Info - Base: (`3.16.0a0`) - [`a646c99`](https://www.github.com/python/cpython/commit/a646c99ee12fbf421394a74955d42fd3fe850b7e) (commit date: 2026-07-31 16:18:49+00:00) - Imported: (`3.16.0a0`) - [`7b4165b`](https://www.github.com/python/cpython/commit/7b4165b3b07638d8aeab79a880c52f2b51c56f37) (commit date: 2026-08-01 19:54:04+00:00) # Noteworthy file changes - Low-signal files (3 added) (NEWS.d, docs, .github) Complete list of added/removed files: https://www.internalfb.com/intern/everpaste/?color=0&handle=GJqWfC0NOZZN-6MDABOP4Fp6mmMSbr0LAAAz Reviewed By: itamaro Differential Revision: D114507654 fbshipit-source-id: 4c8d0adc6c51375d478ef2fd0b64437669049c67
1 parent 8d2cff8 commit 1e45fd2

18 files changed

Lines changed: 93 additions & 31 deletions

File tree

.github/workflows/build.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -338,7 +338,7 @@ jobs:
338338
with:
339339
persist-credentials: false
340340
- name: Build and test
341-
run: JAVA_HOME="${JAVA_HOME_21_X64:-$JAVA_HOME_21_arm64}" python3 Platforms/Android ci --fast-ci ${{ matrix.arch }}-linux-android
341+
run: python3 Platforms/Android ci --fast-ci ${{ matrix.arch }}-linux-android
342342

343343
build-ios:
344344
name: iOS

Include/internal/pycore_lock.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,11 @@ _PyMutex_at_fork_reinit(PyMutex *m)
3434

3535
typedef enum _PyLockFlags {
3636
// Do not detach/release the GIL when waiting on the lock.
37+
//
38+
// Note that code executed while holding a mutex with this flag must
39+
// not detach, reach a safepoint or initiate a stop-the-world pause.
40+
// Otherwise, a non-detaching waiter may remain waiting for this mutex and
41+
// prevent the pause from completing.
3742
_Py_LOCK_DONT_DETACH = 0,
3843

3944
// Detach/release the GIL while waiting on the lock.

Lib/test/test_asyncio/test_tasks.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2924,6 +2924,16 @@ async def coro():
29242924
with self.assertRaises(AttributeError):
29252925
del task._log_destroy_pending
29262926

2927+
def test_get_context_uninitialized_segfault(self):
2928+
# https://github.com/python/cpython/issues/154871
2929+
2930+
class UninitializedTask(self.Task):
2931+
def __init__(self, *args, **kwargs):
2932+
pass
2933+
2934+
task = UninitializedTask()
2935+
self.assertIsNone(task.get_context())
2936+
29272937

29282938
@unittest.skipUnless(hasattr(futures, '_CFuture') and
29292939
hasattr(tasks, '_CTask'),

Lib/test/test_free_threading/test_collections.py

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import unittest
2-
from collections import deque
2+
from collections import OrderedDict, deque
33
from copy import copy
44
from test.support import threading_helper
55

@@ -49,5 +49,30 @@ def mutate():
4949
)
5050

5151

52+
class TestOrderedDict(unittest.TestCase):
53+
def test_iterator_update_clear_race(self):
54+
# gh-151627: OrderedDict iterator construction must not race with
55+
# concurrent clear()/update() operations that mutate the linked list.
56+
od = OrderedDict((i, i) for i in range(100))
57+
58+
def mutate():
59+
for i in range(5000):
60+
od.clear()
61+
od.update(((i, i), (i + 1, i + 1), (i + 2, i + 2)))
62+
63+
def iterate():
64+
for _ in range(5000):
65+
try:
66+
for _ in od:
67+
pass
68+
list(reversed(od))
69+
except RuntimeError:
70+
pass
71+
72+
threading_helper.run_concurrently(
73+
[mutate, *[iterate for _ in range(8)]],
74+
)
75+
76+
5277
if __name__ == "__main__":
5378
unittest.main()

Lib/test/test_zoneinfo/test_zoneinfo.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -316,6 +316,18 @@ def test_unambiguous(self):
316316
self.assertEqual(dt.utcoffset(), offset.utcoffset, dt)
317317
self.assertEqual(dt.dst(), offset.dst, dt)
318318

319+
def test_datetime_subclass_negative_components(self):
320+
class MinusOneDateTime(datetime):
321+
hour = minute = second = -1
322+
323+
zi = self.zone_from_key("UTC")
324+
dt = MinusOneDateTime(2024, 1, 1, tzinfo=zi)
325+
326+
self.assertEqual(dt.utcoffset(), ZERO)
327+
self.assertEqual(dt.dst(), ZERO)
328+
self.assertEqual(dt.tzname(), "UTC")
329+
self.assertEqual(zi.fromutc(dt), datetime(2024, 1, 1, tzinfo=zi))
330+
319331
def test_folds_and_gaps(self):
320332
test_cases = []
321333
for key in self.zones():
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
Fix a crash in :class:`collections.OrderedDict` iterators in free-threaded
2+
builds when the dictionary is concurrently cleared or updated.
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
Fixed a crash in :meth:`asyncio.Task.get_context`
2+
when called on an uninitialized task.
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
Fix a bug in the C accelerator for :mod:`zoneinfo` where
2+
:class:`datetime.datetime` subclasses returning ``-1`` for ``hour``,
3+
``minute``, or ``second`` could incorrectly raise a :exc:`SystemError`.

Modules/_asynciomodule.c

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2786,7 +2786,11 @@ static PyObject *
27862786
_asyncio_Task_get_context_impl(TaskObj *self)
27872787
/*[clinic end generated code: output=6996f53d3dc01aef input=87c0b209b8fceeeb]*/
27882788
{
2789-
return Py_NewRef(self->task_context);
2789+
if (self->task_context) {
2790+
return Py_NewRef(self->task_context);
2791+
}
2792+
2793+
Py_RETURN_NONE;
27902794
}
27912795

27922796
/*[clinic input]

Modules/_zoneinfo.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2311,7 +2311,7 @@ get_local_timestamp(PyObject *dt, int64_t *local_ts)
23112311
}
23122312
hour = PyLong_AsLong(num);
23132313
Py_DECREF(num);
2314-
if (hour == -1) {
2314+
if (hour == -1 && PyErr_Occurred()) {
23152315
return -1;
23162316
}
23172317

@@ -2321,7 +2321,7 @@ get_local_timestamp(PyObject *dt, int64_t *local_ts)
23212321
}
23222322
minute = PyLong_AsLong(num);
23232323
Py_DECREF(num);
2324-
if (minute == -1) {
2324+
if (minute == -1 && PyErr_Occurred()) {
23252325
return -1;
23262326
}
23272327

@@ -2331,7 +2331,7 @@ get_local_timestamp(PyObject *dt, int64_t *local_ts)
23312331
}
23322332
second = PyLong_AsLong(num);
23332333
Py_DECREF(num);
2334-
if (second == -1) {
2334+
if (second == -1 && PyErr_Occurred()) {
23352335
return -1;
23362336
}
23372337
}

0 commit comments

Comments
 (0)