Skip to content

Commit 79d6c7e

Browse files
committed
Merge remote-tracking branch 'upstream/main' into 3.14-whatsnew
2 parents ae5335f + 120c9d4 commit 79d6c7e

File tree

134 files changed

+6213
-1174
lines changed

Some content is hidden

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

134 files changed

+6213
-1174
lines changed

Doc/c-api/init_config.rst

+9-3
Original file line numberDiff line numberDiff line change
@@ -363,7 +363,7 @@ Configuration Options
363363
- Read-only
364364
* - ``"import_time"``
365365
- :c:member:`import_time <PyConfig.import_time>`
366-
- ``bool``
366+
- ``int``
367367
- Read-only
368368
* - ``"inspect"``
369369
- :c:member:`inspect <PyConfig.inspect>`
@@ -1477,13 +1477,19 @@ PyConfig
14771477
14781478
.. c:member:: int import_time
14791479
1480-
If non-zero, profile import time.
1480+
If ``1``, profile import time.
1481+
If ``2``, include additional output that indicates
1482+
when an imported module has already been loaded.
14811483
1482-
Set the ``1`` by the :option:`-X importtime <-X>` option and the
1484+
Set by the :option:`-X importtime <-X>` option and the
14831485
:envvar:`PYTHONPROFILEIMPORTTIME` environment variable.
14841486
14851487
Default: ``0``.
14861488
1489+
.. versionchanged:: next
1490+
1491+
Added support for ``import_time = 2``
1492+
14871493
.. c:member:: int inspect
14881494
14891495
Enter interactive mode after executing a script or a command.

Doc/library/gc.rst

+2-2
Original file line numberDiff line numberDiff line change
@@ -128,8 +128,8 @@ The :mod:`gc` module provides the following functions:
128128
starts. For each collection, all the objects in the young generation and some
129129
fraction of the old generation is collected.
130130

131-
In the free-threaded build, the increase in process resident set size (RSS)
132-
is also checked before running the collector. If the RSS has not increased
131+
In the free-threaded build, the increase in process memory usage is also
132+
checked before running the collector. If the memory usage has not increased
133133
by 10% since the last collection and the net number of object allocations
134134
has not exceeded 40 times *threshold0*, the collection is not run.
135135

Doc/library/sys.rst

+58
Original file line numberDiff line numberDiff line change
@@ -1282,6 +1282,64 @@ always available. Unless explicitly noted otherwise, all variables are read-only
12821282

12831283
.. versionadded:: 3.5
12841284

1285+
.. data:: _jit
1286+
1287+
Utilities for observing just-in-time compilation.
1288+
1289+
.. impl-detail::
1290+
1291+
JIT compilation is an *experimental implementation detail* of CPython.
1292+
``sys._jit`` is not guaranteed to exist or behave the same way in all
1293+
Python implementations, versions, or build configurations.
1294+
1295+
.. versionadded:: next
1296+
1297+
.. function:: _jit.is_available()
1298+
1299+
Return ``True`` if the current Python executable supports JIT compilation,
1300+
and ``False`` otherwise. This can be controlled by building CPython with
1301+
the ``--experimental-jit`` option on Windows, and the
1302+
:option:`--enable-experimental-jit` option on all other platforms.
1303+
1304+
.. function:: _jit.is_enabled()
1305+
1306+
Return ``True`` if JIT compilation is enabled for the current Python
1307+
process (implies :func:`sys._jit.is_available`), and ``False`` otherwise.
1308+
If JIT compilation is available, this can be controlled by setting the
1309+
:envvar:`PYTHON_JIT` environment variable to ``0`` (disabled) or ``1``
1310+
(enabled) at interpreter startup.
1311+
1312+
.. function:: _jit.is_active()
1313+
1314+
Return ``True`` if the topmost Python frame is currently executing JIT
1315+
code (implies :func:`sys._jit.is_enabled`), and ``False`` otherwise.
1316+
1317+
.. note::
1318+
1319+
This function is intended for testing and debugging the JIT itself.
1320+
It should be avoided for any other purpose.
1321+
1322+
.. note::
1323+
1324+
Due to the nature of tracing JIT compilers, repeated calls to this
1325+
function may give surprising results. For example, branching on its
1326+
return value will likely lead to unexpected behavior (if doing so
1327+
causes JIT code to be entered or exited):
1328+
1329+
.. code-block:: pycon
1330+
1331+
>>> for warmup in range(BIG_NUMBER):
1332+
... # This line is "hot", and is eventually JIT-compiled:
1333+
... if sys._jit.is_active():
1334+
... # This line is "cold", and is run in the interpreter:
1335+
... assert sys._jit.is_active()
1336+
...
1337+
Traceback (most recent call last):
1338+
File "<stdin>", line 5, in <module>
1339+
assert sys._jit.is_active()
1340+
~~~~~~~~~~~~~~~~~~^^
1341+
AssertionError
1342+
12851343
.. data:: last_exc
12861344

12871345
This variable is not always defined; it is set to the exception instance

Doc/library/typing.rst

+40
Original file line numberDiff line numberDiff line change
@@ -1098,6 +1098,12 @@ These can be used as types in annotations. They all support subscription using
10981098

10991099
Union[Union[int, str], float] == Union[int, str, float]
11001100

1101+
However, this does not apply to unions referenced through a type
1102+
alias, to avoid forcing evaluation of the underlying :class:`TypeAliasType`::
1103+
1104+
type A = Union[int, str]
1105+
Union[A, float] != Union[int, str, float]
1106+
11011107
* Unions of a single argument vanish, e.g.::
11021108

11031109
Union[int] == int # The constructor actually returns int
@@ -1230,6 +1236,32 @@ These can be used as types in annotations. They all support subscription using
12301236
is allowed as type argument to ``Literal[...]``, but type checkers may
12311237
impose restrictions. See :pep:`586` for more details about literal types.
12321238

1239+
Additional details:
1240+
1241+
* The arguments must be literal values and there must be at least one.
1242+
1243+
* Nested ``Literal`` types are flattened, e.g.::
1244+
1245+
assert Literal[Literal[1, 2], 3] == Literal[1, 2, 3]
1246+
1247+
However, this does not apply to ``Literal`` types referenced through a type
1248+
alias, to avoid forcing evaluation of the underlying :class:`TypeAliasType`::
1249+
1250+
type A = Literal[1, 2]
1251+
assert Literal[A, 3] != Literal[1, 2, 3]
1252+
1253+
* Redundant arguments are skipped, e.g.::
1254+
1255+
assert Literal[1, 2, 1] == Literal[1, 2]
1256+
1257+
* When comparing literals, the argument order is ignored, e.g.::
1258+
1259+
assert Literal[1, 2] == Literal[2, 1]
1260+
1261+
* You cannot subclass or instantiate a ``Literal``.
1262+
1263+
* You cannot write ``Literal[X][Y]``.
1264+
12331265
.. versionadded:: 3.8
12341266

12351267
.. versionchanged:: 3.9.1
@@ -1400,6 +1432,14 @@ These can be used as types in annotations. They all support subscription using
14001432
int, ValueRange(3, 10), ctype("char")
14011433
]
14021434

1435+
However, this does not apply to ``Annotated`` types referenced through a type
1436+
alias, to avoid forcing evaluation of the underlying :class:`TypeAliasType`::
1437+
1438+
type From3To10[T] = Annotated[T, ValueRange(3, 10)]
1439+
assert Annotated[From3To10[int], ctype("char")] != Annotated[
1440+
int, ValueRange(3, 10), ctype("char")
1441+
]
1442+
14031443
Duplicated metadata elements are not removed::
14041444

14051445
assert Annotated[int, ValueRange(3, 10)] != Annotated[

Doc/using/cmdline.rst

+27-4
Original file line numberDiff line numberDiff line change
@@ -539,11 +539,21 @@ Miscellaneous options
539539
* ``-X importtime`` to show how long each import takes. It shows module
540540
name, cumulative time (including nested imports) and self time (excluding
541541
nested imports). Note that its output may be broken in multi-threaded
542-
application. Typical usage is ``python3 -X importtime -c 'import
543-
asyncio'``. See also :envvar:`PYTHONPROFILEIMPORTTIME`.
542+
application. Typical usage is ``python -X importtime -c 'import asyncio'``.
543+
544+
``-X importtime=2`` enables additional output that indicates when an
545+
imported module has already been loaded. In such cases, the string
546+
``cached`` will be printed in both time columns.
547+
548+
See also :envvar:`PYTHONPROFILEIMPORTTIME`.
544549

545550
.. versionadded:: 3.7
546551

552+
.. versionchanged:: next
553+
554+
Added ``-X importtime=2`` to also trace imports of loaded modules,
555+
and reserved values other than ``1`` and ``2`` for future use.
556+
547557
* ``-X dev``: enable :ref:`Python Development Mode <devmode>`, introducing
548558
additional runtime checks that are too expensive to be enabled by
549559
default. See also :envvar:`PYTHONDEVMODE`.
@@ -982,12 +992,17 @@ conflict.
982992

983993
.. envvar:: PYTHONPROFILEIMPORTTIME
984994

985-
If this environment variable is set to a non-empty string, Python will
986-
show how long each import takes.
995+
If this environment variable is set to ``1``, Python will show
996+
how long each import takes. If set to ``2``, Python will include output for
997+
imported modules that have already been loaded.
987998
This is equivalent to setting the :option:`-X` ``importtime`` option.
988999

9891000
.. versionadded:: 3.7
9901001

1002+
.. versionchanged:: next
1003+
1004+
Added ``PYTHONPROFILEIMPORTTIME=2`` to also trace imports of loaded modules.
1005+
9911006

9921007
.. envvar:: PYTHONASYNCIODEBUG
9931008

@@ -1279,6 +1294,14 @@ conflict.
12791294

12801295
.. versionadded:: 3.14
12811296

1297+
.. envvar:: PYTHON_JIT
1298+
1299+
On builds where experimental just-in-time compilation is available, this
1300+
variable can force the JIT to be disabled (``0``) or enabled (``1``) at
1301+
interpreter startup.
1302+
1303+
.. versionadded:: 3.13
1304+
12821305
Debug-mode variables
12831306
~~~~~~~~~~~~~~~~~~~~
12841307

Doc/using/configure.rst

+15-8
Original file line numberDiff line numberDiff line change
@@ -302,14 +302,21 @@ General Options
302302

303303
.. option:: --enable-experimental-jit=[no|yes|yes-off|interpreter]
304304

305-
Indicate how to integrate the :ref:`JIT compiler <whatsnew313-jit-compiler>`.
306-
307-
* ``no`` - build the interpreter without the JIT.
308-
* ``yes`` - build the interpreter with the JIT.
309-
* ``yes-off`` - build the interpreter with the JIT but disable it by default.
310-
* ``interpreter`` - build the interpreter without the JIT, but with the tier 2 enabled interpreter.
311-
312-
By convention, ``--enable-experimental-jit`` is a shorthand for ``--enable-experimental-jit=yes``.
305+
Indicate how to integrate the :ref:`experimental just-in-time compiler <whatsnew314-jit-compiler>`.
306+
307+
* ``no``: Don't build the JIT.
308+
* ``yes``: Enable the JIT. To disable it at runtime, set the environment
309+
variable :envvar:`PYTHON_JIT=0 <PYTHON_JIT>`.
310+
* ``yes-off``: Build the JIT, but disable it by default. To enable it at
311+
runtime, set the environment variable :envvar:`PYTHON_JIT=1 <PYTHON_JIT>`.
312+
* ``interpreter``: Enable the "JIT interpreter" (only useful for those
313+
debugging the JIT itself). To disable it at runtime, set the environment
314+
variable :envvar:`PYTHON_JIT=0 <PYTHON_JIT>`.
315+
316+
``--enable-experimental-jit=no`` is the default behavior if the option is not
317+
provided, and ``--enable-experimental-jit`` is shorthand for
318+
``--enable-experimental-jit=yes``. See :file:`Tools/jit/README.md` for more
319+
information, including how to install the necessary build-time dependencies.
313320

314321
.. note::
315322

Doc/using/windows.rst

+19
Original file line numberDiff line numberDiff line change
@@ -529,6 +529,25 @@ depending on whether it was installed from python.org or through the Windows
529529
Store. Attempting to run the executable directly from Program Files is not
530530
recommended.
531531

532+
To programmatically install or uninstall the MSIX without using your
533+
distribution platform's native support, the `Add-AppxPackage
534+
<https://learn.microsoft.com/powershell/module/appx/add-appxpackage>`_ and
535+
`Remove-AppxPackage <https://learn.microsoft.com/powershell/module/appx/remove-appxpackage>`_
536+
PowerShell cmdlets are simplest to use:
537+
538+
.. code::
539+
540+
$> Add-AppxPackage C:\Downloads\python-manager-25.0.msix
541+
...
542+
$> Get-AppxPackage PythonSoftwareFoundation.PythonManager | Remove-AppxPackage
543+
544+
The native APIs for package management may be found on the Windows
545+
`PackageManager <https://learn.microsoft.com/uwp/api/windows.management.deployment.packagemanager>`_
546+
class. The :func:`!AddPackageAsync` method installs for the current user, or use
547+
:func:`!StagePackageAsync` followed by :func:`!ProvisionPackageForAllUsersAsync`
548+
to install the Python install manager for all users from the MSIX package. Users
549+
will still need to install their own copies of Python itself, as there is no way
550+
to trigger those installs without being a logged in user.
532551

533552
.. _pymanager-admin-config:
534553

0 commit comments

Comments
 (0)