Skip to content

Commit ca06d61

Browse files
authored
Merge branch 'main' into gh-134381-main
2 parents 5e0158c + 77eade3 commit ca06d61

File tree

210 files changed

+2804
-1985
lines changed

Some content is hidden

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

210 files changed

+2804
-1985
lines changed

.github/workflows/build.yml

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,13 @@ permissions:
1515
contents: read
1616

1717
concurrency:
18-
group: ${{ github.workflow }}-${{ github.head_ref || github.run_id }}-reusable
18+
# https://docs.github.com/en/actions/writing-workflows/workflow-syntax-for-github-actions#concurrency
19+
# 'group' must be a key uniquely representing a PR or push event.
20+
# github.workflow is the workflow name
21+
# github.actor is the user invoking the workflow
22+
# github.head_ref is the source branch of the PR or otherwise blank
23+
# github.run_id is a unique number for the current run
24+
group: ${{ github.workflow }}-${{ github.actor }}-${{ github.head_ref || github.run_id }}
1925
cancel-in-progress: true
2026

2127
env:

Doc/howto/annotations.rst

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -248,4 +248,9 @@ quirks by using :func:`annotationlib.get_annotations` on Python 3.14+ or
248248
:func:`inspect.get_annotations` on Python 3.10+. On earlier versions of
249249
Python, you can avoid these bugs by accessing the annotations from the
250250
class's :attr:`~type.__dict__`
251-
(e.g., ``cls.__dict__.get('__annotations__', None)``).
251+
(for example, ``cls.__dict__.get('__annotations__', None)``).
252+
253+
In some versions of Python, instances of classes may have an ``__annotations__``
254+
attribute. However, this is not supported functionality. If you need the
255+
annotations of an instance, you can use :func:`type` to access its class
256+
(for example, ``annotationlib.get_annotations(type(myinstance))`` on Python 3.14+).

Doc/howto/free-threading-python.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ optionally support installing free-threaded Python binaries. The installers
3232
are available at https://www.python.org/downloads/.
3333

3434
For information on other platforms, see the `Installing a Free-Threaded Python
35-
<https://py-free-threading.github.io/installing_cpython/>`_, a
35+
<https://py-free-threading.github.io/installing-cpython/>`_, a
3636
community-maintained installation guide for installing free-threaded Python.
3737

3838
When building CPython from source, the :option:`--disable-gil` configure option

Doc/howto/isolating-extensions.rst

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -215,21 +215,36 @@ multiple interpreters correctly. If this is not yet the case for your
215215
module, you can explicitly make your module loadable only once per
216216
process. For example::
217217

218+
// A process-wide flag
218219
static int loaded = 0;
219220

221+
// Mutex to provide thread safety (only needed for free-threaded Python)
222+
static PyMutex modinit_mutex = {0};
223+
220224
static int
221225
exec_module(PyObject* module)
222226
{
227+
PyMutex_Lock(&modinit_mutex);
223228
if (loaded) {
229+
PyMutex_Unlock(&modinit_mutex);
224230
PyErr_SetString(PyExc_ImportError,
225231
"cannot load module more than once per process");
226232
return -1;
227233
}
228234
loaded = 1;
235+
PyMutex_Unlock(&modinit_mutex);
229236
// ... rest of initialization
230237
}
231238

232239

240+
If your module's :c:member:`PyModuleDef.m_clear` function is able to prepare
241+
for future re-initialization, it should clear the ``loaded`` flag.
242+
In this case, your module won't support multiple instances existing
243+
*concurrently*, but it will, for example, support being loaded after
244+
Python runtime shutdown (:c:func:`Py_FinalizeEx`) and re-initialization
245+
(:c:func:`Py_Initialize`).
246+
247+
233248
Module State Access from Functions
234249
----------------------------------
235250

Doc/library/asyncio-eventloop.rst

Lines changed: 23 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -361,7 +361,7 @@ Creating Futures and Tasks
361361

362362
.. versionadded:: 3.5.2
363363

364-
.. method:: loop.create_task(coro, *, name=None, context=None, eager_start=None)
364+
.. method:: loop.create_task(coro, *, name=None, context=None, eager_start=None, **kwargs)
365365

366366
Schedule the execution of :ref:`coroutine <coroutine>` *coro*.
367367
Return a :class:`Task` object.
@@ -370,6 +370,10 @@ Creating Futures and Tasks
370370
for interoperability. In this case, the result type is a subclass
371371
of :class:`Task`.
372372

373+
The full function signature is largely the same as that of the
374+
:class:`Task` constructor (or factory) - all of the keyword arguments to
375+
this function are passed through to that interface.
376+
373377
If the *name* argument is provided and not ``None``, it is set as
374378
the name of the task using :meth:`Task.set_name`.
375379

@@ -388,8 +392,15 @@ Creating Futures and Tasks
388392
.. versionchanged:: 3.11
389393
Added the *context* parameter.
390394

395+
.. versionchanged:: 3.13.3
396+
Added ``kwargs`` which passes on arbitrary extra parameters, including ``name`` and ``context``.
397+
398+
.. versionchanged:: 3.13.4
399+
Rolled back the change that passes on *name* and *context* (if it is None),
400+
while still passing on other arbitrary keyword arguments (to avoid breaking backwards compatibility with 3.13.3).
401+
391402
.. versionchanged:: 3.14
392-
Added the *eager_start* parameter.
403+
All *kwargs* are now passed on. The *eager_start* parameter works with eager task factories.
393404

394405
.. method:: loop.set_task_factory(factory)
395406

@@ -402,6 +413,16 @@ Creating Futures and Tasks
402413
event loop, and *coro* is a coroutine object. The callable
403414
must pass on all *kwargs*, and return a :class:`asyncio.Task`-compatible object.
404415

416+
.. versionchanged:: 3.13.3
417+
Required that all *kwargs* are passed on to :class:`asyncio.Task`.
418+
419+
.. versionchanged:: 3.13.4
420+
*name* is no longer passed to task factories. *context* is no longer passed
421+
to task factories if it is ``None``.
422+
423+
.. versionchanged:: 3.14
424+
*name* and *context* are now unconditionally passed on to task factories again.
425+
405426
.. method:: loop.get_task_factory()
406427

407428
Return a task factory or ``None`` if the default one is in use.

Doc/library/asyncio-task.rst

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -238,18 +238,24 @@ Creating Tasks
238238

239239
-----------------------------------------------
240240

241-
.. function:: create_task(coro, *, name=None, context=None)
241+
.. function:: create_task(coro, *, name=None, context=None, eager_start=None, **kwargs)
242242

243243
Wrap the *coro* :ref:`coroutine <coroutine>` into a :class:`Task`
244244
and schedule its execution. Return the Task object.
245245

246-
If *name* is not ``None``, it is set as the name of the task using
247-
:meth:`Task.set_name`.
246+
The full function signature is largely the same as that of the
247+
:class:`Task` constructor (or factory) - all of the keyword arguments to
248+
this function are passed through to that interface.
248249

249250
An optional keyword-only *context* argument allows specifying a
250251
custom :class:`contextvars.Context` for the *coro* to run in.
251252
The current context copy is created when no *context* is provided.
252253

254+
An optional keyword-only *eager_start* argument allows specifying
255+
if the task should execute eagerly during the call to create_task,
256+
or be scheduled later. If *eager_start* is not passed the mode set
257+
by :meth:`loop.set_task_factory` will be used.
258+
253259
The task is executed in the loop returned by :func:`get_running_loop`,
254260
:exc:`RuntimeError` is raised if there is no running loop in
255261
current thread.
@@ -290,6 +296,9 @@ Creating Tasks
290296
.. versionchanged:: 3.11
291297
Added the *context* parameter.
292298

299+
.. versionchanged:: 3.14
300+
Added the *eager_start* parameter by passing on all *kwargs*.
301+
293302

294303
Task Cancellation
295304
=================
@@ -330,7 +339,7 @@ and reliable way to wait for all tasks in the group to finish.
330339

331340
.. versionadded:: 3.11
332341

333-
.. method:: create_task(coro, *, name=None, context=None)
342+
.. method:: create_task(coro, *, name=None, context=None, eager_start=None, **kwargs)
334343

335344
Create a task in this task group.
336345
The signature matches that of :func:`asyncio.create_task`.
@@ -342,6 +351,10 @@ and reliable way to wait for all tasks in the group to finish.
342351

343352
Close the given coroutine if the task group is not active.
344353

354+
.. versionchanged:: 3.14
355+
356+
Passes on all *kwargs* to :meth:`loop.create_task`
357+
345358
Example::
346359

347360
async def main():

Doc/library/hashlib.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -284,7 +284,7 @@ a file or file-like object.
284284
Example:
285285

286286
>>> import io, hashlib, hmac
287-
>>> with open(hashlib.__file__, "rb") as f:
287+
>>> with open("library/hashlib.rst", "rb") as f:
288288
... digest = hashlib.file_digest(f, "sha256")
289289
...
290290
>>> digest.hexdigest() # doctest: +ELLIPSIS

Doc/library/stdtypes.rst

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1788,8 +1788,14 @@ expression support in the :mod:`re` module).
17881788

17891789
Return centered in a string of length *width*. Padding is done using the
17901790
specified *fillchar* (default is an ASCII space). The original string is
1791-
returned if *width* is less than or equal to ``len(s)``.
1791+
returned if *width* is less than or equal to ``len(s)``. For example::
17921792

1793+
>>> 'Python'.center(10)
1794+
' Python '
1795+
>>> 'Python'.center(10, '-')
1796+
'--Python--'
1797+
>>> 'Python'.center(4)
1798+
'Python'
17931799

17941800

17951801
.. method:: str.count(sub[, start[, end]])
@@ -1799,8 +1805,18 @@ expression support in the :mod:`re` module).
17991805
interpreted as in slice notation.
18001806

18011807
If *sub* is empty, returns the number of empty strings between characters
1802-
which is the length of the string plus one.
1803-
1808+
which is the length of the string plus one. For example::
1809+
1810+
>>> 'spam, spam, spam'.count('spam')
1811+
3
1812+
>>> 'spam, spam, spam'.count('spam', 5)
1813+
2
1814+
>>> 'spam, spam, spam'.count('spam', 5, 10)
1815+
1
1816+
>>> 'spam, spam, spam'.count('eggs')
1817+
0
1818+
>>> 'spam, spam, spam'.count('')
1819+
17
18041820

18051821
.. method:: str.encode(encoding="utf-8", errors="strict")
18061822

Doc/tools/templates/customsourcelink.html

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
{%- if show_source and has_source and sourcename %}
22
<div role="note" aria-label="source link">
3-
<h3>{{ _('This Page') }}</h3>
3+
<h3>{{ _('This page') }}</h3>
44
<ul class="this-page-menu">
5-
<li><a href="{{ pathto('bugs') }}">{% trans %}Report a Bug{% endtrans %}</a></li>
5+
<li><a href="{{ pathto('bugs') }}">{% trans %}Report a bug{% endtrans %}</a></li>
66
<li>
77
<a href="https://github.com/python/cpython/blob/main/Doc/{{ sourcename|replace('.rst.txt', '.rst') }}"
8-
rel="nofollow">{{ _('Show Source') }}
8+
rel="nofollow">{{ _('Show source') }}
99
</a>
1010
</li>
1111
</ul>

Doc/tools/templates/download.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@
2727
{%- endblock -%}
2828

2929
{% block body %}
30-
<h1>{% trans %}Download Python {{ dl_version }} Documentation{% endtrans %}</h1>
30+
<h1>{% trans %}Download Python {{ dl_version }} documentation{% endtrans %}</h1>
3131

3232
{% if last_updated %}<p><b>{% trans %}Last updated on: {{ last_updated }}.{% endtrans %}</b></p>{% endif %}
3333

Doc/tools/templates/indexcontent.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ <h1>{{ docstitle|e }}</h1>
7272
<table class="contentstable" align="center"><tr>
7373
<td width="50%">
7474
<p class="biglink"><a class="biglink" href="{{ pathto("bugs") }}">{% trans %}Reporting issues{% endtrans %}</a></p>
75-
<p class="biglink"><a class="biglink" href="https://devguide.python.org/documentation/help-documenting/">{% trans %}Contributing to Docs{% endtrans %}</a></p>
75+
<p class="biglink"><a class="biglink" href="https://devguide.python.org/documentation/help-documenting/">{% trans %}Contributing to docs{% endtrans %}</a></p>
7676
<p class="biglink"><a class="biglink" href="{{ pathto("download") }}">{% trans %}Download the documentation{% endtrans %}</a></p>
7777
</td><td width="50%">
7878
<p class="biglink"><a class="biglink" href="{{ pathto("license") }}">{% trans %}History and license of Python{% endtrans %}</a></p>

Doc/tools/templates/indexsidebar.html

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,9 @@ <h3>{% trans %}Docs by version{% endtrans %}</h3>
99
<h3>{% trans %}Other resources{% endtrans %}</h3>
1010
<ul>
1111
{# XXX: many of these should probably be merged in the main docs #}
12-
<li><a href="https://peps.python.org/">{% trans %}PEP Index{% endtrans %}</a></li>
13-
<li><a href="https://wiki.python.org/moin/BeginnersGuide">{% trans %}Beginner's Guide{% endtrans %}</a></li>
14-
<li><a href="https://wiki.python.org/moin/PythonBooks">{% trans %}Book List{% endtrans %}</a></li>
15-
<li><a href="https://www.python.org/doc/av/">{% trans %}Audio/Visual Talks{% endtrans %}</a></li>
16-
<li><a href="https://devguide.python.org/">{% trans %}Python Developer’s Guide{% endtrans %}</a></li>
12+
<li><a href="https://peps.python.org/">{% trans %}PEP index{% endtrans %}</a></li>
13+
<li><a href="https://wiki.python.org/moin/BeginnersGuide">{% trans %}Beginner's guide{% endtrans %}</a></li>
14+
<li><a href="https://wiki.python.org/moin/PythonBooks">{% trans %}Book list{% endtrans %}</a></li>
15+
<li><a href="https://www.python.org/doc/av/">{% trans %}Audio/visual talks{% endtrans %}</a></li>
16+
<li><a href="https://devguide.python.org/">{% trans %}Python developer’s guide{% endtrans %}</a></li>
1717
</ul>

Doc/tutorial/index.rst

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,10 @@
44
The Python Tutorial
55
######################
66

7+
.. Tip:: This tutorial is designed for
8+
*programmers* that are new to the Python language,
9+
**not** *beginners* who are new to programming.
10+
711
Python is an easy to learn, powerful programming language. It has efficient
812
high-level data structures and a simple but effective approach to
913
object-oriented programming. Python's elegant syntax and dynamic typing,
@@ -21,7 +25,8 @@ implemented in C or C++ (or other languages callable from C). Python is also
2125
suitable as an extension language for customizable applications.
2226

2327
This tutorial introduces the reader informally to the basic concepts and
24-
features of the Python language and system. It helps to have a Python
28+
features of the Python language and system. Be aware that it expects you to
29+
have a basic understanding of programming in general. It helps to have a Python
2530
interpreter handy for hands-on experience, but all examples are self-contained,
2631
so the tutorial can be read off-line as well.
2732

Doc/using/windows.rst

Lines changed: 34 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -504,6 +504,14 @@ configuration option.
504504
installing and uninstalling.
505505
506506
507+
.. _Add-AppxPackage: https://learn.microsoft.com/powershell/module/appx/add-appxpackage
508+
509+
.. _Remove-AppxPackage: https://learn.microsoft.com/powershell/module/appx/remove-appxpackage
510+
511+
.. _Add-AppxProvisionedPackage: https://learn.microsoft.com/powershell/module/dism/add-appxprovisionedpackage
512+
513+
.. _PackageManager: https://learn.microsoft.com/uwp/api/windows.management.deployment.packagemanager
514+
507515
.. _pymanager-advancedinstall:
508516

509517
Advanced Installation
@@ -559,31 +567,44 @@ downloaded MSIX can be installed by launching or using the commands below.
559567

560568
.. code-block:: powershell
561569
562-
$> winget download 9NQ7512CXL7T -e --skip-license --accept-package-agreements --disable-interactivity
570+
$> winget download 9NQ7512CXL7T -e --skip-license --accept-package-agreements --accept-source-agreements
563571
564572
To programmatically install or uninstall an MSIX using only PowerShell, the
565-
`Add-AppxPackage <https://learn.microsoft.com/powershell/module/appx/add-appxpackage>`_
566-
and `Remove-AppxPackage <https://learn.microsoft.com/powershell/module/appx/remove-appxpackage>`_
567-
PowerShell cmdlets are recommended:
573+
`Add-AppxPackage`_ and `Remove-AppxPackage`_ PowerShell cmdlets are recommended:
568574

569575
.. code-block:: powershell
570576
571577
$> Add-AppxPackage C:\Downloads\python-manager-25.0.msix
572578
...
573579
$> Get-AppxPackage PythonSoftwareFoundation.PythonManager | Remove-AppxPackage
574580
575-
The native APIs for package management may be found on the Windows
576-
`PackageManager <https://learn.microsoft.com/uwp/api/windows.management.deployment.packagemanager>`_
577-
class. The :func:`!AddPackageAsync` method installs for the current user, or use
578-
:func:`!StagePackageAsync` followed by :func:`!ProvisionPackageForAllUsersAsync`
579-
to install the Python install manager for all users from the MSIX package. Users
580-
will still need to install their own copies of Python itself, as there is no way
581-
to trigger those installs without being a logged in user.
581+
The latest release can be downloaded and installed by Windows by passing the
582+
AppInstaller file to the Add-AppxPackage command. This installs using the MSIX
583+
on python.org, and is only recommended for cases where installing via the Store
584+
(interactively or using WinGet) is not possible.
585+
586+
.. code-block:: powershell
587+
588+
$> Add-AppxPackage -AppInstallerFile https://www.python.org/ftp/python/pymanager/pymanager.appinstaller
589+
590+
Other tools and APIs may also be used to provision an MSIX package for all users
591+
on a machine, but Python does not consider this a supported scenario. We suggest
592+
looking into the PowerShell `Add-AppxProvisionedPackage`_ cmdlet, the native
593+
Windows `PackageManager`_ class, or the documentation and support for your
594+
deployment tool.
595+
596+
Regardless of the install method, users will still need to install their own
597+
copies of Python itself, as there is no way to trigger those installs without
598+
being a logged in user. When using the MSIX, the latest version of Python will
599+
be available for all users to install without network access.
582600

583601
Note that the MSIX downloadable from the Store and from the Python website are
584602
subtly different and cannot be installed at the same time. Wherever possible,
585-
we suggest using the above commands to download the package from the Store to
586-
reduce the risk of setting up conflicting installs.
603+
we suggest using the above WinGet commands to download the package from the
604+
Store to reduce the risk of setting up conflicting installs. There are no
605+
licensing restrictions on the Python install manager that would prevent using
606+
the Store package in this way.
607+
587608

588609
.. _pymanager-admin-config:
589610

Include/internal/pycore_backoff.h

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -95,8 +95,10 @@ backoff_counter_triggers(_Py_BackoffCounter counter)
9595
return counter.value_and_backoff < UNREACHABLE_BACKOFF;
9696
}
9797

98-
/* Initial JUMP_BACKWARD counter.
99-
* This determines when we create a trace for a loop. */
98+
// Initial JUMP_BACKWARD counter.
99+
// Must be larger than ADAPTIVE_COOLDOWN_VALUE, otherwise when JIT code is
100+
// invalidated we may construct a new trace before the bytecode has properly
101+
// re-specialized:
100102
#define JUMP_BACKWARD_INITIAL_VALUE 4095
101103
#define JUMP_BACKWARD_INITIAL_BACKOFF 12
102104
static inline _Py_BackoffCounter

Include/internal/pycore_code.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -451,6 +451,9 @@ write_location_entry_start(uint8_t *ptr, int code, int length)
451451
#define ADAPTIVE_COOLDOWN_BACKOFF 0
452452

453453
// Can't assert this in pycore_backoff.h because of header order dependencies
454+
#if JUMP_BACKWARD_INITIAL_VALUE <= ADAPTIVE_COOLDOWN_VALUE
455+
# error "JIT threshold value should be larger than adaptive cooldown value"
456+
#endif
454457
#if SIDE_EXIT_INITIAL_VALUE <= ADAPTIVE_COOLDOWN_VALUE
455458
# error "Cold exit value should be larger than adaptive cooldown value"
456459
#endif

0 commit comments

Comments
 (0)