Skip to content

Commit 8e7023d

Browse files
Merge branch 'main' into poptimize
2 parents 2d5f428 + 5e2f0b9 commit 8e7023d

File tree

94 files changed

+1902
-343
lines changed

Some content is hidden

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

94 files changed

+1902
-343
lines changed

.github/workflows/jit.yml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,10 @@ jobs:
117117
find /usr/local/bin -lname '*/Library/Frameworks/Python.framework/*' -delete
118118
brew install llvm@${{ matrix.llvm }}
119119
export SDKROOT="$(xcrun --show-sdk-path)"
120+
# Set MACOSX_DEPLOYMENT_TARGET and -Werror=unguarded-availability to
121+
# make sure we don't break downstream distributors (like uv):
122+
export CFLAGS_JIT='-Werror=unguarded-availability'
123+
export MACOSX_DEPLOYMENT_TARGET=10.15
120124
./configure --enable-experimental-jit --enable-universalsdk --with-universal-archs=universal2 ${{ matrix.debug && '--with-pydebug' || '' }}
121125
make all --jobs 4
122126
./python.exe -m test --multiprocess 0 --timeout 4500 --verbose2 --verbose3

Doc/library/array.rst

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ defined:
2424
+-----------+--------------------+-------------------+-----------------------+-------+
2525
| ``'u'`` | wchar_t | Unicode character | 2 | \(1) |
2626
+-----------+--------------------+-------------------+-----------------------+-------+
27-
| ``'w'`` | Py_UCS4 | Unicode character | 4 | |
27+
| ``'w'`` | Py_UCS4 | Unicode character | 4 | \(2) |
2828
+-----------+--------------------+-------------------+-----------------------+-------+
2929
| ``'h'`` | signed short | int | 2 | |
3030
+-----------+--------------------+-------------------+-----------------------+-------+
@@ -60,6 +60,9 @@ Notes:
6060
.. deprecated-removed:: 3.3 3.16
6161
Please migrate to ``'w'`` typecode.
6262

63+
(2)
64+
.. versionadded:: 3.13
65+
6366

6467
The actual representation of values is determined by the machine architecture
6568
(strictly speaking, by the C implementation). The actual size can be accessed

Doc/library/asyncio-eventloop.rst

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -611,6 +611,12 @@ Opening network connections
611611
to bind the socket locally. The *local_host* and *local_port*
612612
are looked up using :meth:`getaddrinfo`.
613613

614+
.. note::
615+
616+
On Windows, when using the proactor event loop with ``local_addr=None``,
617+
an :exc:`OSError` with :attr:`!errno.WSAEINVAL` will be raised
618+
when running it.
619+
614620
* *remote_addr*, if given, is a ``(remote_host, remote_port)`` tuple used
615621
to connect the socket to a remote address. The *remote_host* and
616622
*remote_port* are looked up using :meth:`getaddrinfo`.

Doc/library/bisect.rst

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,16 @@ method to determine whether a value has been found. Instead, the
2424
functions only call the :meth:`~object.__lt__` method and will return an insertion
2525
point between values in an array.
2626

27+
.. note::
28+
29+
The functions in this module are not thread-safe. If multiple threads
30+
concurrently use :mod:`bisect` functions on the same sequence, this
31+
may result in undefined behaviour. Likewise, if the provided sequence
32+
is mutated by a different thread while a :mod:`bisect` function
33+
is operating on it, the result is undefined. For example, using
34+
:py:func:`~bisect.insort_left` on the same list from multiple threads
35+
may result in the list becoming unsorted.
36+
2737
.. _bisect functions:
2838

2939
The following functions are provided:

Doc/library/codecs.rst

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1483,6 +1483,36 @@ to :class:`bytes` mappings. They are not supported by :meth:`bytes.decode`
14831483
Restoration of the aliases for the binary transforms.
14841484

14851485

1486+
.. _standalone-codec-functions:
1487+
1488+
Standalone Codec Functions
1489+
^^^^^^^^^^^^^^^^^^^^^^^^^^
1490+
1491+
The following functions provide encoding and decoding functionality similar to codecs,
1492+
but are not available as named codecs through :func:`codecs.encode` or :func:`codecs.decode`.
1493+
They are used internally (for example, by :mod:`pickle`) and behave similarly to the
1494+
``string_escape`` codec that was removed in Python 3.
1495+
1496+
.. function:: codecs.escape_encode(input, errors=None)
1497+
1498+
Encode *input* using escape sequences. Similar to how :func:`repr` on bytes
1499+
produces escaped byte values.
1500+
1501+
*input* must be a :class:`bytes` object.
1502+
1503+
Returns a tuple ``(output, length)`` where *output* is a :class:`bytes`
1504+
object and *length* is the number of bytes consumed.
1505+
1506+
.. function:: codecs.escape_decode(input, errors=None)
1507+
1508+
Decode *input* from escape sequences back to the original bytes.
1509+
1510+
*input* must be a :term:`bytes-like object`.
1511+
1512+
Returns a tuple ``(output, length)`` where *output* is a :class:`bytes`
1513+
object and *length* is the number of bytes consumed.
1514+
1515+
14861516
.. _text-transforms:
14871517

14881518
Text Transforms

Doc/library/concurrent.futures.rst

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -342,6 +342,11 @@ that :class:`ProcessPoolExecutor` will not work in the interactive interpreter.
342342
Calling :class:`Executor` or :class:`Future` methods from a callable submitted
343343
to a :class:`ProcessPoolExecutor` will result in deadlock.
344344

345+
Note that the restrictions on functions and arguments needing to picklable as
346+
per :class:`multiprocessing.Process` apply when using :meth:`~Executor.submit`
347+
and :meth:`~Executor.map` on a :class:`ProcessPoolExecutor`. A function defined
348+
in a REPL or a lambda should not be expected to work.
349+
345350
.. class:: ProcessPoolExecutor(max_workers=None, mp_context=None, initializer=None, initargs=(), max_tasks_per_child=None)
346351

347352
An :class:`Executor` subclass that executes calls asynchronously using a pool

Doc/library/heapq.rst

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -231,6 +231,42 @@ Heap elements can be tuples. This is useful for assigning comparison values
231231
(1, 'write spec')
232232

233233

234+
Other Applications
235+
------------------
236+
237+
`Medians <https://en.wikipedia.org/wiki/Median>`_ are a measure of
238+
central tendency for a set of numbers. In distributions skewed by
239+
outliers, the median provides a more stable estimate than an average
240+
(arithmetic mean). A running median is an `online algorithm
241+
<https://en.wikipedia.org/wiki/Online_algorithm>`_ that updates
242+
continuously as new data arrives.
243+
244+
A running median can be efficiently implemented by balancing two heaps,
245+
a max-heap for values at or below the midpoint and a min-heap for values
246+
above the midpoint. When the two heaps have the same size, the new
247+
median is the average of the tops of the two heaps; otherwise, the
248+
median is at the top of the larger heap::
249+
250+
def running_median(iterable):
251+
"Yields the cumulative median of values seen so far."
252+
253+
lo = [] # max-heap
254+
hi = [] # min-heap (same size as or one smaller than lo)
255+
256+
for x in iterable:
257+
if len(lo) == len(hi):
258+
heappush_max(lo, heappushpop(hi, x))
259+
yield lo[0]
260+
else:
261+
heappush(hi, heappushpop_max(lo, x))
262+
yield (lo[0] + hi[0]) / 2
263+
264+
For example::
265+
266+
>>> list(running_median([5.0, 9.0, 4.0, 12.0, 8.0, 9.0]))
267+
[5.0, 7.0, 5.0, 7.0, 8.0, 8.5]
268+
269+
234270
Priority Queue Implementation Notes
235271
-----------------------------------
236272

Doc/library/http.cookies.rst

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -148,9 +148,12 @@ Morsel Objects
148148
in HTTP requests, and is not accessible through JavaScript. This is intended
149149
to mitigate some forms of cross-site scripting.
150150

151-
The attribute :attr:`samesite` specifies that the browser is not allowed to
152-
send the cookie along with cross-site requests. This helps to mitigate CSRF
153-
attacks. Valid values for this attribute are "Strict" and "Lax".
151+
The attribute :attr:`samesite` controls when the browser sends the cookie with
152+
cross-site requests. This helps to mitigate CSRF attacks. Valid values are
153+
"Strict" (only sent with same-site requests), "Lax" (sent with same-site
154+
requests and top-level navigations), and "None" (sent with same-site and
155+
cross-site requests). When using "None", the "secure" attribute must also
156+
be set, as required by modern browsers.
154157

155158
The attribute :attr:`partitioned` indicates to user agents that these
156159
cross-site cookies *should* only be available in the same top-level context

Doc/library/multiprocessing.rst

Lines changed: 48 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,10 @@ To show the individual process IDs involved, here is an expanded example::
9797
For an explanation of why the ``if __name__ == '__main__'`` part is
9898
necessary, see :ref:`multiprocessing-programming`.
9999

100+
The arguments to :class:`Process` usually need to be unpickleable from within
101+
the child process. If you tried typing the above example directly into a REPL it
102+
could lead to an :exc:`AttributeError` in the child process trying to locate the
103+
*f* function in the ``__main__`` module.
100104

101105

102106
.. _multiprocessing-start-methods:
@@ -233,9 +237,12 @@ processes for a different context. In particular, locks created using
233237
the *fork* context cannot be passed to processes started using the
234238
*spawn* or *forkserver* start methods.
235239

236-
A library which wants to use a particular start method should probably
237-
use :func:`get_context` to avoid interfering with the choice of the
238-
library user.
240+
Libraries using :mod:`multiprocessing` or
241+
:class:`~concurrent.futures.ProcessPoolExecutor` should be designed to allow
242+
their users to provide their own multiprocessing context. Using a specific
243+
context of your own within a library can lead to incompatibilities with the
244+
rest of the library user's application. Always document if your library
245+
requires a specific start method.
239246

240247
.. warning::
241248

@@ -538,9 +545,42 @@ The :mod:`multiprocessing` package mostly replicates the API of the
538545
to pass to *target*.
539546

540547
If a subclass overrides the constructor, it must make sure it invokes the
541-
base class constructor (:meth:`Process.__init__`) before doing anything else
548+
base class constructor (``super().__init__()``) before doing anything else
542549
to the process.
543550

551+
.. note::
552+
553+
In general, all arguments to :class:`Process` must be picklable. This is
554+
frequently observed when trying to create a :class:`Process` or use a
555+
:class:`concurrent.futures.ProcessPoolExecutor` from a REPL with a
556+
locally defined *target* function.
557+
558+
Passing a callable object defined in the current REPL session causes the
559+
child process to die via an uncaught :exc:`AttributeError` exception when
560+
starting as *target* must have been defined within an importable module
561+
in order to be loaded during unpickling.
562+
563+
Example of this uncatchable error from the child::
564+
565+
>>> import multiprocessing as mp
566+
>>> def knigit():
567+
... print("Ni!")
568+
...
569+
>>> process = mp.Process(target=knigit)
570+
>>> process.start()
571+
>>> Traceback (most recent call last):
572+
File ".../multiprocessing/spawn.py", line ..., in spawn_main
573+
File ".../multiprocessing/spawn.py", line ..., in _main
574+
AttributeError: module '__main__' has no attribute 'knigit'
575+
>>> process
576+
<SpawnProcess name='SpawnProcess-1' pid=379473 parent=378707 stopped exitcode=1>
577+
578+
See :ref:`multiprocessing-programming-spawn`. While this restriction is
579+
not true if using the ``"fork"`` start method, as of Python ``3.14`` that
580+
is no longer the default on any platform. See
581+
:ref:`multiprocessing-start-methods`.
582+
See also :gh:`132898`.
583+
544584
.. versionchanged:: 3.3
545585
Added the *daemon* parameter.
546586

@@ -3070,10 +3110,10 @@ start method.
30703110

30713111
More picklability
30723112

3073-
Ensure that all arguments to :meth:`Process.__init__` are picklable.
3074-
Also, if you subclass :class:`~multiprocessing.Process` then make sure that
3075-
instances will be picklable when the :meth:`Process.start
3076-
<multiprocessing.Process.start>` method is called.
3113+
Ensure that all arguments to :class:`~multiprocessing.Process` are
3114+
picklable. Also, if you subclass ``Process.__init__``, you must make sure
3115+
that instances will be picklable when the
3116+
:meth:`Process.start <multiprocessing.Process.start>` method is called.
30773117

30783118
Global variables
30793119

Doc/library/os.path.rst

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -424,6 +424,8 @@ the :mod:`glob` module.)
424424
re-raised.
425425
In particular, :exc:`FileNotFoundError` is raised if *path* does not exist,
426426
or another :exc:`OSError` if it is otherwise inaccessible.
427+
If *strict* is :data:`ALL_BUT_LAST`, the last component of the path
428+
is allowed to be missing, but all other errors are raised.
427429

428430
If *strict* is :py:data:`os.path.ALLOW_MISSING`, errors other than
429431
:exc:`FileNotFoundError` are re-raised (as with ``strict=True``).
@@ -448,15 +450,22 @@ the :mod:`glob` module.)
448450
The *strict* parameter was added.
449451

450452
.. versionchanged:: next
451-
The :py:data:`~os.path.ALLOW_MISSING` value for the *strict* parameter
452-
was added.
453+
The :data:`ALL_BUT_LAST` and :data:`ALLOW_MISSING` values for
454+
the *strict* parameter was added.
455+
456+
.. data:: ALL_BUT_LAST
457+
458+
Special value used for the *strict* argument in :func:`realpath`.
459+
460+
.. versionadded:: next
453461

454462
.. data:: ALLOW_MISSING
455463

456464
Special value used for the *strict* argument in :func:`realpath`.
457465

458466
.. versionadded:: next
459467

468+
460469
.. function:: relpath(path, start=os.curdir)
461470

462471
Return a relative filepath to *path* either from the current directory or

0 commit comments

Comments
 (0)