Skip to content

Commit 8d6e099

Browse files
committed
Merge branch 'main'
2 parents fd7baee + b625601 commit 8d6e099

File tree

155 files changed

+8607
-3929
lines changed

Some content is hidden

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

155 files changed

+8607
-3929
lines changed

.gitattributes

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,8 @@ Lib/test/test_stable_abi_ctypes.py generated
9494
Lib/test/test_zoneinfo/data/*.json generated
9595
Lib/token.py generated
9696
Misc/sbom.spdx.json generated
97+
Modules/_testinternalcapi/test_cases.c.h generated
98+
Modules/_testinternalcapi/test_targets.h generated
9799
Objects/typeslots.inc generated
98100
PC/python3dll.c generated
99101
Parser/parser.c generated

Android/testbed/app/build.gradle.kts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,12 @@ android {
9292
}
9393
throw GradleException("Failed to find API level in $androidEnvFile")
9494
}
95-
targetSdk = 35
95+
96+
// This controls the API level of the maxVersion managed emulator, which is used
97+
// by CI and cibuildwheel. 34 takes up too much disk space (#142289), 35 has
98+
// issues connecting to the internet (#142387), and 36 and later are not
99+
// available as aosp_atd images yet.
100+
targetSdk = 33
96101

97102
versionCode = 1
98103
versionName = "1.0"

Doc/c-api/memory.rst

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -677,7 +677,11 @@ The pymalloc allocator
677677
Python has a *pymalloc* allocator optimized for small objects (smaller or equal
678678
to 512 bytes) with a short lifetime. It uses memory mappings called "arenas"
679679
with a fixed size of either 256 KiB on 32-bit platforms or 1 MiB on 64-bit
680-
platforms. It falls back to :c:func:`PyMem_RawMalloc` and
680+
platforms. When Python is configured with :option:`--with-pymalloc-hugepages`,
681+
the arena size on 64-bit platforms is increased to 2 MiB to match the huge page
682+
size, and arena allocation will attempt to use huge pages (``MAP_HUGETLB`` on
683+
Linux, ``MEM_LARGE_PAGES`` on Windows) with automatic fallback to regular pages.
684+
It falls back to :c:func:`PyMem_RawMalloc` and
681685
:c:func:`PyMem_RawRealloc` for allocations larger than 512 bytes.
682686
683687
*pymalloc* is the :ref:`default allocator <default-memory-allocators>` of the

Doc/c-api/module.rst

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -426,10 +426,10 @@ To retrieve the state from a given module, use the following functions:
426426
module state.
427427
428428
429-
.. c:function:: int PyModule_GetStateSize(PyObject *, Py_ssize_t *result)
429+
.. c:function:: int PyModule_GetStateSize(PyObject *module, Py_ssize_t *result)
430430
431-
Set *\*result* to the size of the module's state, as specified using
432-
:c:macro:`Py_mod_state_size` (or :c:member:`PyModuleDef.m_size`),
431+
Set *\*result* to the size of *module*'s state, as specified
432+
using :c:macro:`Py_mod_state_size` (or :c:member:`PyModuleDef.m_size`),
433433
and return 0.
434434
435435
On error, set *\*result* to -1, and return -1 with an exception set.
@@ -597,7 +597,7 @@ A module's token -- and the *your_token* value to use in the above code -- is:
597597
598598
.. c:function:: int PyModule_GetToken(PyObject *module, void** result)
599599
600-
Set *\*result* to the module's token and return 0.
600+
Set *\*result* to the module token for *module* and return 0.
601601
602602
On error, set *\*result* to NULL, and return -1 with an exception set.
603603
@@ -645,7 +645,7 @@ rather than from an extension's :ref:`export hook <extension-export-hook>`.
645645
646646
.. c:function:: int PyModule_Exec(PyObject *module)
647647
648-
Execute the :c:data:`Py_mod_exec` slot(s) of the given *module*.
648+
Execute the :c:data:`Py_mod_exec` slot(s) of *module*.
649649
650650
On success, return 0.
651651
On error, return -1 with an exception set.
@@ -1021,6 +1021,9 @@ or code that creates modules dynamically.
10211021
``PyModuleDef`` (such as when using :ref:`multi-phase-initialization`,
10221022
``PyModule_Create``, or ``PyModule_FromDefAndSpec``).
10231023
1024+
Return ``0`` on success.
1025+
Return ``-1`` with an exception set on error.
1026+
10241027
.. versionadded:: 3.5
10251028
10261029
.. c:function:: int PyUnstable_Module_SetGIL(PyObject *module, void *gil)

Doc/library/base64.rst

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,7 @@ POST request.
7373

7474

7575
.. function:: b64decode(s, altchars=None, validate=False)
76+
b64decode(s, altchars=None, validate=True, *, ignorechars)
7677
7778
Decode the Base64 encoded :term:`bytes-like object` or ASCII string
7879
*s* and return the decoded :class:`bytes`.
@@ -84,11 +85,17 @@ POST request.
8485
A :exc:`binascii.Error` exception is raised
8586
if *s* is incorrectly padded.
8687

87-
If *validate* is false (the default), characters that are neither
88+
If *ignorechars* is specified, it should be a :term:`bytes-like object`
89+
containing characters to ignore from the input when *validate* is true.
90+
The default value of *validate* is ``True`` if *ignorechars* is specified,
91+
``False`` otherwise.
92+
93+
If *validate* is false, characters that are neither
8894
in the normal base-64 alphabet nor the alternative alphabet are
8995
discarded prior to the padding check, but the ``+`` and ``/`` characters
9096
keep their meaning if they are not in *altchars* (they will be discarded
9197
in future Python versions).
98+
9299
If *validate* is true, these non-alphabet characters in the input
93100
result in a :exc:`binascii.Error`.
94101

@@ -99,6 +106,10 @@ POST request.
99106
is now deprecated.
100107

101108

109+
.. versionchanged:: next
110+
Added the *ignorechars* parameter.
111+
112+
102113
.. function:: standard_b64encode(s)
103114

104115
Encode :term:`bytes-like object` *s* using the standard Base64 alphabet

Doc/library/binascii.rst

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,10 +49,16 @@ The :mod:`binascii` module defines the following functions:
4949

5050

5151
.. function:: a2b_base64(string, /, *, strict_mode=False)
52+
a2b_base64(string, /, *, strict_mode=True, ignorechars)
5253
5354
Convert a block of base64 data back to binary and return the binary data. More
5455
than one line may be passed at a time.
5556

57+
If *ignorechars* is specified, it should be a :term:`bytes-like object`
58+
containing characters to ignore from the input when *strict_mode* is true.
59+
The default value of *strict_mode* is ``True`` if *ignorechars* is specified,
60+
``False`` otherwise.
61+
5662
If *strict_mode* is true, only valid base64 data will be converted. Invalid base64
5763
data will raise :exc:`binascii.Error`.
5864

@@ -66,6 +72,9 @@ The :mod:`binascii` module defines the following functions:
6672
.. versionchanged:: 3.11
6773
Added the *strict_mode* parameter.
6874

75+
.. versionchanged:: next
76+
Added the *ignorechars* parameter.
77+
6978

7079
.. function:: b2a_base64(data, *, wrapcol=0, newline=True)
7180

Doc/library/contextvars.rst

Lines changed: 31 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,32 @@ Context Variables
7777
to restore the variable to its previous value via the
7878
:meth:`ContextVar.reset` method.
7979

80+
For convenience, the token object can be used as a context manager
81+
to avoid calling :meth:`ContextVar.reset` manually::
82+
83+
var = ContextVar('var', default='default value')
84+
85+
with var.set('new value'):
86+
assert var.get() == 'new value'
87+
88+
assert var.get() == 'default value'
89+
90+
It is a shorthand for::
91+
92+
var = ContextVar('var', default='default value')
93+
94+
token = var.set('new value')
95+
try:
96+
assert var.get() == 'new value'
97+
finally:
98+
var.reset(token)
99+
100+
assert var.get() == 'default value'
101+
102+
.. versionadded:: 3.14
103+
104+
Added support for using tokens as context managers.
105+
80106
.. method:: reset(token)
81107

82108
Reset the context variable to the value it had before the
@@ -93,24 +119,18 @@ Context Variables
93119
# After the reset call the var has no value again, so
94120
# var.get() would raise a LookupError.
95121

122+
The same *token* cannot be used twice.
123+
96124

97125
.. class:: Token
98126

99127
*Token* objects are returned by the :meth:`ContextVar.set` method.
100128
They can be passed to the :meth:`ContextVar.reset` method to revert
101129
the value of the variable to what it was before the corresponding
102-
*set*.
103-
104-
The token supports :ref:`context manager protocol <context-managers>`
105-
to restore the corresponding context variable value at the exit from
106-
:keyword:`with` block::
107-
108-
var = ContextVar('var', default='default value')
109-
110-
with var.set('new value'):
111-
assert var.get() == 'new value'
130+
*set*. A single token cannot reset a context variable more than once.
112131

113-
assert var.get() == 'default value'
132+
Tokens support the :ref:`context manager protocol <context-managers>`
133+
to automatically reset context variables. See :meth:`ContextVar.set`.
114134

115135
.. versionadded:: 3.14
116136

Doc/library/os.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4262,7 +4262,7 @@ features:
42624262
import os
42634263

42644264
# semaphore with start value '1'
4265-
fd = os.eventfd(1, os.EFD_SEMAPHORE | os.EFC_CLOEXEC)
4265+
fd = os.eventfd(1, os.EFD_SEMAPHORE | os.EFD_CLOEXEC)
42664266
try:
42674267
# acquire semaphore
42684268
v = os.eventfd_read(fd)

Doc/library/pickle.rst

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -56,19 +56,6 @@ files.
5656

5757
The :mod:`pickle` module differs from :mod:`marshal` in several significant ways:
5858

59-
* The :mod:`pickle` module keeps track of the objects it has already serialized,
60-
so that later references to the same object won't be serialized again.
61-
:mod:`marshal` doesn't do this.
62-
63-
This has implications both for recursive objects and object sharing. Recursive
64-
objects are objects that contain references to themselves. These are not
65-
handled by marshal, and in fact, attempting to marshal recursive objects will
66-
crash your Python interpreter. Object sharing happens when there are multiple
67-
references to the same object in different places in the object hierarchy being
68-
serialized. :mod:`pickle` stores such objects only once, and ensures that all
69-
other references point to the master copy. Shared objects remain shared, which
70-
can be very important for mutable objects.
71-
7259
* :mod:`marshal` cannot be used to serialize user-defined classes and their
7360
instances. :mod:`pickle` can save and restore class instances transparently,
7461
however the class definition must be importable and live in the same module as

Doc/library/subprocess.rst

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -803,14 +803,29 @@ Instances of the :class:`Popen` class have the following methods:
803803

804804
.. note::
805805

806-
When the ``timeout`` parameter is not ``None``, then (on POSIX) the
807-
function is implemented using a busy loop (non-blocking call and short
808-
sleeps). Use the :mod:`asyncio` module for an asynchronous wait: see
806+
When ``timeout`` is not ``None`` and the platform supports it, an
807+
efficient event-driven mechanism is used to wait for process termination:
808+
809+
- Linux >= 5.3 uses :func:`os.pidfd_open` + :func:`select.poll`
810+
- macOS and other BSD variants use :func:`select.kqueue` +
811+
``KQ_FILTER_PROC`` + ``KQ_NOTE_EXIT``
812+
- Windows uses ``WaitForSingleObject``
813+
814+
If none of these mechanisms are available, the function falls back to a
815+
busy loop (non-blocking call and short sleeps).
816+
817+
.. note::
818+
819+
Use the :mod:`asyncio` module for an asynchronous wait: see
809820
:class:`asyncio.create_subprocess_exec`.
810821

811822
.. versionchanged:: 3.3
812823
*timeout* was added.
813824

825+
.. versionchanged:: 3.15
826+
if *timeout* is not ``None``, use efficient event-driven implementation
827+
on Linux >= 5.3 and macOS / BSD.
828+
814829
.. method:: Popen.communicate(input=None, timeout=None)
815830

816831
Interact with process: Send data to stdin. Read data from stdout and stderr,

0 commit comments

Comments
 (0)