Skip to content

Commit 36d1ce5

Browse files
generatedunixname1734921407115435meta-codesync[bot]
authored andcommitted
Sync pre-release CPython main branch from GitHub (2026-07-28)
Summary: Imported python/cpython `3.16.0a0` from upstream rev [`c8eb79d`](https://www.github.com/python/cpython/commit/c8eb79d5e89196449992fe50978d6b8845dc6681) (committed 2026-07-28 05:00:39+00:00). # Commit Info - Base: (`3.16.0a0`) - [`993a0c6`](https://www.github.com/python/cpython/commit/993a0c65a7b1836aa2087dff197b2fffa62d5b4f) (commit date: 2026-07-26 22:37:20+00:00) - Imported: (`3.16.0a0`) - [`c8eb79d`](https://www.github.com/python/cpython/commit/c8eb79d5e89196449992fe50978d6b8845dc6681) (commit date: 2026-07-28 05:00:39+00:00) # Noteworthy file changes - Test files (3 added) - Low-signal files (6 added, 1 removed) (NEWS.d, docs, .github) Complete list of added/removed files: https://www.internalfb.com/intern/everpaste/?color=0&handle=GLzr7hzVqf6sfRwGAAYX2f5-i05Dbr0LAAAz Reviewed By: itamaro Differential Revision: D113872493 fbshipit-source-id: d3ea73f29eb1b2b90a42f02e7eded63b113bdab9
1 parent 6b9166e commit 36d1ce5

39 files changed

Lines changed: 1145 additions & 82 deletions

Doc/c-api/sys.rst

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -433,7 +433,7 @@ accessible to C code. They all work with the current interpreter thread's
433433
This function is safe to call before :c:func:`Py_Initialize`. When called
434434
after runtime initialization, existing audit hooks are notified and may
435435
silently abort the operation by raising an error subclassed from
436-
:class:`Exception` (other errors will not be silenced).
436+
:class:`RuntimeError` (other errors will not be silenced).
437437
438438
The hook function is always called with an :term:`attached thread state` by
439439
the Python interpreter that raised the event.
@@ -447,7 +447,7 @@ accessible to C code. They all work with the current interpreter thread's
447447
448448
If the interpreter is initialized, this function raises an auditing event
449449
``sys.addaudithook`` with no arguments. If any existing hooks raise an
450-
exception derived from :class:`Exception`, the new hook will not be
450+
exception derived from :class:`RuntimeError`, the new hook will not be
451451
added and the exception is cleared. As a result, callers cannot assume
452452
that their hook has been added unless they control all existing hooks.
453453
@@ -462,6 +462,11 @@ accessible to C code. They all work with the current interpreter thread's
462462
463463
.. versionadded:: 3.8
464464
465+
.. versionchanged:: 3.8.1
466+
467+
Exceptions derived from :class:`Exception` but not :class:`RuntimeError`
468+
are no longer suppressed.
469+
465470
466471
.. _processcontrol:
467472

Doc/library/curses.rst

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -129,6 +129,8 @@ Initialization and termination
129129
and return the previously current screen.
130130
Returns ``None`` if the previous screen was the one created by
131131
:func:`initscr`.
132+
Raises :exc:`error` if *screen* has no terminal,
133+
as is the case for a screen returned by :func:`new_prescr`.
132134

133135
.. versionadded:: next
134136

Doc/library/test.rst

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -961,6 +961,59 @@ The :mod:`!test.support` module defines the following functions:
961961
:mod:`tracemalloc` is enabled.
962962

963963

964+
.. currentmodule:: test.support.isolation
965+
966+
.. decorator:: runInSubprocess()
967+
968+
Decorator that runs the decorated test in a fresh interpreter subprocess, in
969+
isolation, so that it does not share global or interpreter state with the
970+
rest of the test run. It can decorate a test method or a whole
971+
:class:`~unittest.TestCase` subclass. Decorated methods must take no extra
972+
arguments. A failure, error or skip in the subprocess is reported for the
973+
corresponding test, and individual :meth:`subtests
974+
<unittest.TestCase.subTest>` that fail or are skipped are reported
975+
individually. A reported failure or error shows the original subprocess
976+
traceback as the cause of the exception.
977+
978+
When a **method** is decorated, only that method runs in a subprocess; all
979+
fixtures (:meth:`~unittest.TestCase.setUp` / :meth:`~unittest.TestCase.tearDown`,
980+
:meth:`~unittest.TestCase.setUpClass` / :meth:`~unittest.TestCase.tearDownClass`
981+
and ``setUpModule()`` / ``tearDownModule()``) run both in the parent process
982+
(as usual) and in the subprocess around the method.
983+
984+
When a **class** is decorated, the whole class runs in a single subprocess,
985+
and :meth:`~unittest.TestCase.setUpClass`,
986+
:meth:`~unittest.TestCase.tearDownClass`, :meth:`~unittest.TestCase.setUp`
987+
and :meth:`~unittest.TestCase.tearDown` run once each in the subprocess and
988+
are skipped in the parent process. A failure or skip of
989+
:meth:`~unittest.TestCase.setUpClass` in the subprocess is reported for the
990+
whole class. ``setUpModule()`` cannot be controlled by a class decorator,
991+
so it still runs in the parent process too; test it with
992+
:data:`runningInSubprocess` if needed.
993+
994+
The subprocess inherits the enabled resources (``-u``), memory limit
995+
(``-M``) and verbosity (``-v``) of the parent test run, so that
996+
:func:`~test.support.requires_resource`, :func:`~test.support.requires`,
997+
:func:`~test.support.bigmemtest` and the like behave consistently in both
998+
processes.
999+
1000+
The test is skipped on platforms without subprocess support.
1001+
1002+
1003+
.. data:: runningInSubprocess
1004+
1005+
``True`` while the code runs in the isolated subprocess spawned by
1006+
:func:`runInSubprocess`, and ``False`` otherwise (including in the parent
1007+
process and in a normal, non-isolated test run). Fixtures such as
1008+
:meth:`~unittest.TestCase.setUp`, :meth:`~unittest.TestCase.tearDown`,
1009+
:meth:`~unittest.TestCase.setUpClass`, :meth:`~unittest.TestCase.tearDownClass`,
1010+
``setUpModule()`` and ``tearDownModule()`` can test it to choose which code
1011+
to run in the subprocess.
1012+
1013+
1014+
.. currentmodule:: test.support
1015+
1016+
9641017
.. function:: check_free_after_iterating(test, iter, cls, args=())
9651018

9661019
Assert instances of *cls* are deallocated after iterating.

Doc/whatsnew/3.15.rst

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -873,6 +873,14 @@ Other language changes
873873
imports ``pkg.sub.mod``.
874874
(Contributed by Gregory P. Smith in :gh:`83065`.)
875875

876+
* File names of Stable ABI extensions that use the ``.so`` suffix may now
877+
include a multiarch tuple, for example, ``foo.abi3-x86-64-linux-gnu.so``.
878+
This permits stable ABI extensions for multiple architectures to be
879+
co-installed into the same directory, without clashing with each
880+
other, as regular dynamic extensions do.
881+
(Contributed by Stefano Rivera in :gh:`122931`.)
882+
883+
876884

877885
Default interactive shell
878886
=========================

Include/internal/pycore_interp_structs.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -977,7 +977,6 @@ struct _is {
977977
struct _obmalloc_state *obmalloc;
978978

979979
PyObject *audit_hooks;
980-
PyMutex audit_hooks_mutex;
981980
PyType_WatchCallback type_watchers[TYPE_MAX_WATCHERS];
982981
PyCode_WatchCallback code_watchers[CODE_MAX_WATCHERS];
983982
PyContext_WatchCallback context_watchers[CONTEXT_MAX_WATCHERS];

Lib/collections/__init__.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -553,6 +553,9 @@ class Counter(dict):
553553
or multiset. Elements are stored as dictionary keys and their counts
554554
are stored as dictionary values.
555555
556+
When constructed from a Mapping or Counter, the original object's
557+
values will be used as the initial counts.
558+
556559
>>> c = Counter('abcdeabcdabcaba') # count elements from a string
557560
558561
>>> c.most_common(3) # three most common elements

Lib/csv.py

Lines changed: 33 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -563,22 +563,40 @@ def _detect_doublequote(self, lines, delimiter, quotechar, escapechar):
563563
def _detect_skipinitialspace(self, lines, delimiter, quotechar,
564564
escapechar, doublequote):
565565
"""
566-
True only if every field following a delimiter starts with
567-
a space.
566+
Detect whether the spaces following a delimiter are a part of
567+
the format or of the data.
568568
"""
569-
skipinitialspace = False
570-
try:
571-
for row in self._make_reader(lines, delimiter, quotechar,
572-
escapechar,
573-
doublequote=doublequote,
574-
skipinitialspace=False):
575-
for field in row[1:]:
576-
if not field.startswith(' '):
577-
return False
578-
skipinitialspace = True
579-
except Error:
580-
pass
581-
return skipinitialspace
569+
results = []
570+
for skipinitialspace in False, True:
571+
rows = []
572+
try:
573+
rows.extend(self._make_reader(
574+
lines, delimiter, quotechar, escapechar,
575+
doublequote=doublequote,
576+
skipinitialspace=skipinitialspace))
577+
except Error:
578+
# Keep the rows parsed before the error.
579+
pass
580+
results.append([row for row in rows if row])
581+
if results[0] == results[1]:
582+
return False # No evidence.
583+
counts = [[len(row) for row in rows] for rows in results]
584+
if counts[0] != counts[1]:
585+
# Prefer the more consistent row widths.
586+
return len(set(counts[1])) <= len(set(counts[0]))
587+
# Only some spaces are stripped. A field differs only if
588+
# a space was skipped at its start, which tells the padding
589+
# apart from the spaces inside quoted or escaped fields.
590+
if not all(kept_field != skipped_field
591+
for kept_row, skipped_row in zip(*results)
592+
for kept_field, skipped_field in zip(kept_row[1:],
593+
skipped_row[1:])):
594+
return False
595+
# The first field of a row is commonly not padded ('a, b, c'),
596+
# so the first fields need only agree with each other.
597+
first = [kept_row[0] != skipped_row[0]
598+
for kept_row, skipped_row in zip(*results)]
599+
return all(first) or not any(first)
582600

583601
def has_header(self, sample):
584602
# Creates a dictionary of types of data in each column. If any

Lib/importlib/abc.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
"""Abstract base classes related to import."""
22
from . import _bootstrap_external
33
from . import machinery
4+
45
try:
56
import _frozen_importlib
67
except ImportError as exc:
@@ -11,10 +12,12 @@
1112
import _frozen_importlib_external
1213
except ImportError:
1314
_frozen_importlib_external = _bootstrap_external
14-
from ._abc import Loader
1515
import abc
1616

1717

18+
# Public API
19+
from ._abc import Loader
20+
1821
__all__ = [
1922
'Loader', 'MetaPathFinder', 'PathEntryFinder',
2023
'ResourceLoader', 'InspectLoader', 'ExecutionLoader',

Lib/importlib/machinery.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
"""The machinery of importlib: finders, loaders, hooks, etc."""
22

3+
lazy import warnings
4+
5+
6+
# Public API
37
from ._bootstrap import ModuleSpec
48
from ._bootstrap import BuiltinImporter
59
from ._bootstrap import FrozenImporter
@@ -33,8 +37,6 @@ def all_suffixes():
3337

3438

3539
def __getattr__(name):
36-
import warnings
37-
3840
if name == 'DEBUG_BYTECODE_SUFFIXES':
3941
warnings.warn('importlib.machinery.DEBUG_BYTECODE_SUFFIXES is '
4042
'deprecated; use importlib.machinery.BYTECODE_SUFFIXES '

Lib/importlib/util.py

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,23 @@
11
"""Utility code for constructing importers, etc."""
2+
3+
from ._bootstrap import _resolve_name
4+
from ._bootstrap import _find_spec
5+
6+
import _imp
7+
import sys
8+
import types
9+
10+
11+
# Public API
212
from ._abc import Loader
313
from ._bootstrap import module_from_spec
4-
from ._bootstrap import _resolve_name
514
from ._bootstrap import spec_from_loader
6-
from ._bootstrap import _find_spec
715
from ._bootstrap_external import MAGIC_NUMBER
816
from ._bootstrap_external import cache_from_source
917
from ._bootstrap_external import decode_source
1018
from ._bootstrap_external import source_from_cache
1119
from ._bootstrap_external import spec_from_file_location
1220

13-
import _imp
14-
import sys
15-
import types
16-
1721

1822
def source_hash(source_bytes):
1923
"Return the hash of *source_bytes* as used in hash-based pyc files."

0 commit comments

Comments
 (0)