Skip to content

Commit d8e144d

Browse files
Merge remote-tracking branch 'upstream/main' into gh-155004-iconv-error-shift-state
# Conflicts: # Lib/test/test_codecs.py
2 parents 51940f7 + 204feba commit d8e144d

40 files changed

Lines changed: 540 additions & 115 deletions

.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

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

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,13 @@ Pending removal in Python 3.17
3737
is deprecated and scheduled for removal in Python 3.17.
3838
(Contributed by Stan Ulbrych in :gh:`136702`.)
3939

40+
* :mod:`profile`:
41+
42+
- The :mod:`!profile` module is deprecated and will be removed in
43+
Python 3.17. Use :mod:`profiling.tracing` instead, which provides a
44+
compatible API. See :pep:`799` for details.
45+
(Contributed by Pablo Galindo and László Kiss Kollár in :gh:`138122`.)
46+
4047
* :mod:`webbrowser`:
4148

4249
- :class:`!webbrowser.MacOSXOSAScript` is deprecated in favour of

Doc/library/decimal.rst

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1182,6 +1182,14 @@ In addition to the three supplied contexts, new contexts can be created with the
11821182

11831183
Return a duplicate of the context.
11841184

1185+
:class:`!Context` objects also support :func:`copy.replace`,
1186+
which returns a duplicate with the specified fields replaced.
1187+
Fields which are not specified keep the values
1188+
they have in the original context.
1189+
1190+
.. versionchanged:: next
1191+
Added support for :func:`copy.replace`.
1192+
11851193
.. method:: copy_decimal(num, /)
11861194

11871195
Return a copy of the Decimal instance num.

Doc/library/functools.rst

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -386,9 +386,9 @@ The :mod:`!functools` module defines the following functions:
386386
only one positional argument is provided, but there are two placeholders
387387
that must be filled in.
388388

389-
If :func:`!partial` is applied to an existing :func:`!partial` object,
390-
:data:`!Placeholder` sentinels of the input object are filled in with
391-
new positional arguments.
389+
If :func:`!partial` is applied to an existing
390+
:ref:`partial object <partial-objects>`, :data:`!Placeholder` sentinels of the
391+
input object are filled in with new positional arguments.
392392
A placeholder can be retained by inserting a new
393393
:data:`!Placeholder` sentinel to the place held by a previous :data:`!Placeholder`:
394394

Doc/whatsnew/3.15.rst

Lines changed: 50 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ Summary -- Release highlights
8585
* :pep:`728`: :ref:`TypedDict with typed extra items <whatsnew315-typeddict>`
8686
* :pep:`747`: :ref:`Annotating type forms with TypeForm
8787
<whatsnew315-typeform>`
88-
* :pep:`800`: Disjoint bases in the type system
88+
* :pep:`800`: :ref:`Disjoint bases in the type system <whatsnew315-disjoint-base>`
8989
* :pep:`782`: :ref:`A new PyBytesWriter C API to create a Python bytes object
9090
<whatsnew315-pybyteswriter>`
9191
* :pep:`803`, :pep:`820 <820>`, :pep:`793 <793>`:
@@ -494,8 +494,8 @@ drive it with :meth:`~site.StartupState.addsitedir`,
494494

495495
.. _whatsnew315-abi3t:
496496

497-
:pep:`803` -- Stable ABI for free-threaded builds
498-
-------------------------------------------------
497+
:pep:`803`: Stable ABI for free-threaded builds
498+
-----------------------------------------------
499499

500500
C extensions that target the :ref:`Stable ABI <stable-abi>` can now be
501501
compiled for the new *Stable ABI for Free-Threaded Builds* (also known
@@ -522,7 +522,7 @@ free-threading (``cp315t``) separately.
522522
Stable ABI for Free-Threaded Builds should typically
523523
be selected in a build tool (such as, for example, Setuptools, meson-python,
524524
scikit-build-core, or Maturin).
525-
At the time of writing, these tools did **not** support ``abi3t``.
525+
At the time of writing, these tools do **not** support ``abi3t``.
526526
If this is the case for your tool, compile for ``cp315t`` separately.
527527
If not using a build tool -- or when writing such a tool -- you can select
528528
``abi3t`` by setting the macro :c:macro:`!Py_TARGET_ABI3T` as discussed
@@ -1103,6 +1103,16 @@ contextlib
11031103
(Contributed by Alex Grönholm & Gregory P. Smith in :gh:`125862`.)
11041104

11051105

1106+
ctypes
1107+
------
1108+
1109+
* Change the :py:attr:`~ctypes._SimpleCData._type_` of
1110+
:class:`~ctypes.c_float_complex`, :class:`~ctypes.c_double_complex` and
1111+
:class:`~ctypes.c_longdouble_complex` from ``F``, ``D`` and ``G`` to ``Zf``,
1112+
``Zd`` and ``Zg`` for compatibility with NumPy.
1113+
(Contributed by Victor Stinner in :gh:`148675`.)
1114+
1115+
11061116
dataclasses
11071117
-----------
11081118

@@ -1229,7 +1239,7 @@ importlib.metadata
12291239
------------------
12301240

12311241
* Previously, when accessing a distribution metadata directory not
1232-
containing a metadata file, ``metadata()`` and ``Distribution.metadata()``
1242+
containing a metadata file, ``metadata()`` and ``Distribution.metadata``
12331243
would return an empty ``PackageMetadata`` object as if the file
12341244
was present but empty. Now, a ``MetadataNotFound`` exception is raised.
12351245
See `importlib_metadata#493 <https://github.com/python/importlib_metadata/issues/493>`_
@@ -1333,6 +1343,14 @@ os.path
13331343
(Contributed by Petr Viktorin for :cve:`2025-4517`.)
13341344

13351345

1346+
pathlib
1347+
-------
1348+
1349+
* :meth:`pathlib.Path.mkdir` now has a *parent_mode* parameter that allows
1350+
specifying the mode for intermediate directories when ``parents=True``.
1351+
(Contributed by Gregory P. Smith in :gh:`86533`.)
1352+
1353+
13361354
pdb
13371355
---
13381356

@@ -1447,7 +1465,7 @@ ssl
14471465
supports "External PSKs" in TLSv1.3, as described in :rfc:`9258`.
14481466
(Contributed by Will Childs-Klein in :gh:`133624`.)
14491467

1450-
* Added new methods for managing groups used for SSL key agreement
1468+
* Added new methods for managing groups used for SSL key agreement:
14511469

14521470
* :meth:`ssl.SSLContext.set_groups` sets the groups allowed for doing
14531471
key agreement, extending the previous
@@ -1726,6 +1744,8 @@ typing
17261744
as it was incorrectly inferred at runtime before.
17271745
(Contributed by Nikita Sobolev in :gh:`137191`.)
17281746

1747+
.. _whatsnew315-disjoint-base:
1748+
17291749
* :pep:`800`: Add :deco:`typing.disjoint_base`, a new decorator marking a class
17301750
as a disjoint base. This is an advanced feature primarily intended to allow
17311751
type checkers to faithfully reflect the runtime semantics of types defined
@@ -1854,8 +1874,8 @@ xml
18541874
whether a string can be used as an element or attribute name in XML.
18551875
(Contributed by Serhiy Storchaka in :gh:`139489`.)
18561876

1857-
* Add the :func:`xml.is_valid_text` function, which allows to check
1858-
whether a string can be used in the XML document.
1877+
* Add the :func:`xml.is_valid_text` function to check
1878+
whether a string can be used in an XML document.
18591879
(Contributed by Serhiy Storchaka in :gh:`139489`.)
18601880

18611881

@@ -1989,8 +2009,8 @@ is now performed. This means when the JIT compiler detects that certain user
19892009
code results in constants, the code can be simplified by the JIT.
19902010
(Contributed by Ken Jin and Savannah Ostrowski in :gh:`132732`.)
19912011

1992-
:term:`Reference count`\ s are avoided whenever it is safe to do so. This generally
1993-
reduces the cost of most operations in Python.
2012+
:term:`Reference counts <reference count>` are avoided whenever it is safe to
2013+
do so. This generally reduces the cost of most operations in Python.
19942014
(Contributed by Ken Jin, Donghee Na, Zheao Li, Hai Zhu, Savannah Ostrowski,
19952015
Reiden Ong, Noam Cohen, Tomas Roun, PuQing, Cajetan Rodrigues, and Sacul in :gh:`134584`.)
19962016

@@ -2058,12 +2078,6 @@ ctypes
20582078
which has been deprecated since Python 3.13.
20592079
(Contributed by Bénédikt Tran in :gh:`133866`.)
20602080

2061-
* Change the :py:attr:`~ctypes._SimpleCData._type_` of
2062-
:class:`~ctypes.c_float_complex`, :class:`~ctypes.c_double_complex` and
2063-
:class:`~ctypes.c_longdouble_complex` from ``F``, ``D`` and ``G`` to ``Zf``,
2064-
``Zd`` and ``Zg`` for compatibility with numpy.
2065-
(Contributed by Victor Stinner in :gh:`148675`.)
2066-
20672081

20682082
datetime
20692083
--------
@@ -2103,10 +2117,6 @@ importlib.resources
21032117
pathlib
21042118
-------
21052119

2106-
* :meth:`pathlib.Path.mkdir` now has a *parent_mode* parameter that allows
2107-
specifying the mode for intermediate directories when ``parents=True``.
2108-
(Contributed by Gregory P. Smith in :gh:`86533`.)
2109-
21102120
* Removed deprecated :meth:`!pathlib.PurePath.is_reserved`.
21112121
Use :func:`os.path.isreserved` to detect reserved paths on Windows.
21122122
(Contributed by Nikita Sobolev in :gh:`133875`.)
@@ -2146,8 +2156,8 @@ threading
21462156
types
21472157
-----
21482158

2149-
* Removed deprecated in :pep:`626` since Python 3.12
2150-
:attr:`!codeobject.co_lnotab` from :class:`types.CodeType`.
2159+
* Removed :attr:`!codeobject.co_lnotab` from :class:`types.CodeType`,
2160+
deprecated since Python 3.12 by :pep:`626`.
21512161
(Contributed by Nikita Sobolev in :gh:`134690`.)
21522162

21532163

@@ -2270,6 +2280,14 @@ New deprecations
22702280
and changing its value does *not* explicitly close the current file.
22712281

22722282

2283+
* :mod:`profile`:
2284+
2285+
* The :mod:`!profile` module is deprecated and will be removed in
2286+
Python 3.17. Use :mod:`profiling.tracing` instead, which provides a
2287+
compatible API. See :pep:`799` for details.
2288+
(Contributed by Pablo Galindo and László Kiss Kollár in :gh:`138122`.)
2289+
2290+
22732291
* :mod:`re`:
22742292

22752293
* :func:`re.match` and :meth:`re.Pattern.match` are now
@@ -2299,8 +2317,8 @@ New deprecations
22992317

23002318
(Contributed by Sergey B Kirpichev and Serhiy Storchaka in :gh:`143715`.)
23012319

2302-
* Using ``'F'`` and ``'D'`` type codes now are :term:`soft deprecated`
2303-
in favor of two-letter forms ``'Zf'`` and ``'Zd'``.
2320+
* The ``'F'`` and ``'D'`` type codes are now :term:`soft deprecated`
2321+
in favor of the two-letter forms ``'Zf'`` and ``'Zd'``.
23042322
(Contributed by Sergey B Kirpichev in :gh:`121249`.)
23052323

23062324

@@ -2413,7 +2431,7 @@ New features
24132431
functions as replacements for :c:func:`PySys_GetObject`.
24142432
(Contributed by Serhiy Storchaka in :gh:`108512`.)
24152433

2416-
* Add :c:type:`PyUnstable_Unicode_GET_CACHED_HASH` to get the cached hash of
2434+
* Add :c:func:`PyUnstable_Unicode_GET_CACHED_HASH` to get the cached hash of
24172435
a string. See the documentation for caveats.
24182436
(Contributed by Petr Viktorin in :gh:`131510`.)
24192437

@@ -2429,14 +2447,14 @@ New features
24292447

24302448
* :c:func:`PyBytesWriter_Create`
24312449
* :c:func:`PyBytesWriter_Discard`
2450+
* :c:func:`PyBytesWriter_Finish`
24322451
* :c:func:`PyBytesWriter_FinishWithPointer`
24332452
* :c:func:`PyBytesWriter_FinishWithSize`
2434-
* :c:func:`PyBytesWriter_Finish`
24352453
* :c:func:`PyBytesWriter_Format`
24362454
* :c:func:`PyBytesWriter_GetData`
24372455
* :c:func:`PyBytesWriter_GetSize`
2438-
* :c:func:`PyBytesWriter_GrowAndUpdatePointer`
24392456
* :c:func:`PyBytesWriter_Grow`
2457+
* :c:func:`PyBytesWriter_GrowAndUpdatePointer`
24402458
* :c:func:`PyBytesWriter_Resize`
24412459
* :c:func:`PyBytesWriter_WriteBytes`
24422460

@@ -2447,7 +2465,7 @@ New features
24472465

24482466
(Contributed in :gh:`149227`.)
24492467

2450-
* Add a new :c:func:`PyImport_CreateModuleFromInitfunc` C-API for creating
2468+
* Add a new :c:func:`PyImport_CreateModuleFromInitfunc` C API for creating
24512469
a module from a *spec* and *initfunc*.
24522470
(Contributed by Itamar Oren in :gh:`116146`.)
24532471

@@ -2521,7 +2539,7 @@ New features
25212539
thread state.
25222540
(Contributed by Victor Stinner in :gh:`139653`.)
25232541

2524-
* Add :c:func:`PyUnstable_SetImmortal` C-API function to mark objects as :term:`immortal`.
2542+
* Add :c:func:`PyUnstable_SetImmortal` C API function to mark objects as :term:`immortal`.
25252543
(Contributed by Kumar Aditya in :gh:`143300`.)
25262544

25272545
* Restore private provisional ``_Py_InitializeMain()`` function removed in
@@ -2714,10 +2732,11 @@ Build changes
27142732
At runtime, huge pages must be explicitly enabled by setting the
27152733
:envvar:`PYTHON_PYMALLOC_HUGEPAGES` environment variable to ``1``.
27162734

2717-
* Annotating anonymous mmap usage is now supported if Linux kernel supports
2735+
* Annotating anonymous mmap usage is now supported if the Linux kernel supports
27182736
:manpage:`PR_SET_VMA_ANON_NAME <PR_SET_VMA(2const)>` (Linux 5.17 or newer).
27192737
Annotations are visible in ``/proc/<pid>/maps`` if the kernel supports the feature
2720-
and :option:`-X dev <-X>` is passed to the Python or Python is built in :ref:`debug mode <debug-build>`.
2738+
and :option:`-X dev <-X>` is passed to Python,
2739+
or Python is built in :ref:`debug mode <debug-build>`.
27212740
(Contributed by Donghee Na in :gh:`141770`.)
27222741

27232742
* CPython is now built with frame pointers enabled by default

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.

InternalDocs/parser.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -545,7 +545,7 @@ by default** except for rules with the special marker `memo` after the rule
545545
name (and type, if present):
546546

547547
```
548-
rule_name[typr] (memo):
548+
rule_name[return_type] (memo):
549549
...
550550
```
551551

@@ -772,7 +772,7 @@ from them or to perform extra processing on the generated tree.
772772
> Actions must **never** be used to accept or reject rules. It may be tempting
773773
> in some situations to write a very generic rule and then check the generated
774774
> AST to decide whether it is valid or not, but this will render the
775-
> (official grammar)[https://docs.python.org/3/reference/grammar.html] partially
775+
> [official grammar](https://docs.python.org/3/reference/grammar.html) partially
776776
> incorrect (because it does not include actions) and will make it more difficult
777777
> for other Python implementations to adapt the grammar to their own needs.
778778
@@ -860,7 +860,7 @@ $ python -d file_to_test.py
860860

861861
This will print **a lot** of output to `stderr` so it is probably better to dump
862862
it to a file for further analysis. The output consists of trace lines with the
863-
following structure::
863+
following structure:
864864

865865
```
866866
<indentation> ('>'|'-'|'+'|'!') <rule_name>[<token_location>]: <alternative> ...

Lib/_pydecimal.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4005,6 +4005,20 @@ def copy(self):
40054005
return nc
40064006
__copy__ = copy
40074007

4008+
def __replace__(self, /, **changes):
4009+
"""Returns a copy of self with the specified attributes replaced."""
4010+
unexpected = changes.keys() - _context_attributes
4011+
if unexpected:
4012+
raise TypeError(f'__replace__() got an unexpected keyword '
4013+
f'argument {min(unexpected)!r}')
4014+
nc = self.copy()
4015+
for name, value in changes.items():
4016+
if name in ('flags', 'traps') and isinstance(value, list):
4017+
# As in the constructor, accept a list of signals.
4018+
value = dict((s, int(s in value)) for s in _signals + value)
4019+
setattr(nc, name, value)
4020+
return nc
4021+
40084022
def _raise_error(self, condition, explanation = None, *args):
40094023
"""Handles an error
40104024

Lib/logging/__init__.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1709,7 +1709,11 @@ def removeHandler(self, hdlr):
17091709
"""
17101710
with _lock:
17111711
if hdlr in self.handlers:
1712-
self.handlers.remove(hdlr)
1712+
# Replace the list instead of mutating it in place, so that
1713+
# callHandlers() can iterate it without a lock (gh-79366).
1714+
handlers = self.handlers.copy()
1715+
handlers.remove(hdlr)
1716+
self.handlers = handlers
17131717

17141718
def hasHandlers(self):
17151719
"""

Lib/shutil.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -292,8 +292,11 @@ def copyfile(src, dst, *, follow_symlinks=True):
292292
if _samefile(src, dst):
293293
raise SameFileError("{!r} and {!r} are the same file".format(src, dst))
294294

295+
copy_symlink = not follow_symlinks and _islink(src)
295296
file_size = 0
296297
for i, fn in enumerate([src, dst]):
298+
if copy_symlink and i == 0:
299+
continue
297300
try:
298301
st = _stat(fn)
299302
except OSError:
@@ -315,7 +318,7 @@ def copyfile(src, dst, *, follow_symlinks=True):
315318
if _WINDOWS and i == 0:
316319
file_size = st.st_size
317320

318-
if not follow_symlinks and _islink(src):
321+
if copy_symlink:
319322
os.symlink(os.readlink(src), dst)
320323
else:
321324
with open(src, 'rb') as fsrc:

0 commit comments

Comments
 (0)