Skip to content

Commit 9f179b4

Browse files
authored
Merge branch 'main' into fixes4
2 parents f926c53 + 448d7b9 commit 9f179b4

91 files changed

Lines changed: 1802 additions & 794 deletions

File tree

Some content is hidden

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

Doc/howto/free-threading-extensions.rst

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -416,11 +416,9 @@ C API extensions need to be built specifically for the free-threaded build.
416416
The wheels, shared libraries, and binaries are indicated by a ``t`` suffix.
417417

418418
* `pypa/manylinux <https://github.com/pypa/manylinux>`_ supports the
419-
free-threaded build, with the ``t`` suffix, such as ``python3.13t``.
420-
* `pypa/cibuildwheel <https://github.com/pypa/cibuildwheel>`_ supports the
421-
free-threaded build on Python 3.13 and 3.14. On Python 3.14, free-threaded
422-
wheels will be built by default. On Python 3.13, you will need to set
423-
`CIBW_ENABLE to cpython-freethreading <https://cibuildwheel.pypa.io/en/stable/options/#enable>`_.
419+
free-threaded build, with the ``t`` suffix, such as ``python3.14t``.
420+
* `pypa/cibuildwheel <https://github.com/pypa/cibuildwheel>`_ supports
421+
building wheels for the free-threaded build of Python 3.14 and newer.
424422

425423
Limited C API and Stable ABI
426424
............................

Doc/library/calendar.rst

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -580,9 +580,14 @@ The :mod:`!calendar` module defines the following exceptions:
580580

581581
.. exception:: IllegalMonthError(month)
582582

583-
A subclass of :exc:`ValueError`,
583+
A subclass of :exc:`ValueError` and :exc:`IndexError`,
584584
raised when the given month number is outside of the range 1-12 (inclusive).
585585

586+
.. versionchanged:: 3.12
587+
:exc:`IllegalMonthError` is now also a subclass of
588+
:exc:`ValueError`. New code should avoid catching
589+
:exc:`IndexError`.
590+
586591
.. attribute:: month
587592

588593
The invalid month number.

Doc/library/collections.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -326,7 +326,7 @@ For example::
326326
.. versionadded:: 3.10
327327

328328
The usual dictionary methods are available for :class:`Counter` objects
329-
except for two which work differently for counters.
329+
except for these two which work differently for counters:
330330

331331
.. method:: fromkeys(iterable)
332332

Doc/library/dataclasses.rst

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -371,8 +371,8 @@ Module contents
371371
Converts the dataclass *obj* to a dict (by using the
372372
factory function *dict_factory*). Each dataclass is converted
373373
to a dict of its fields, as ``name: value`` pairs. dataclasses, dicts,
374-
lists, and tuples are recursed into. Other objects are copied with
375-
:func:`copy.deepcopy`.
374+
frozendicts, lists, and tuples are recursed into. Other objects are copied
375+
with :func:`copy.deepcopy`.
376376

377377
Example of using :func:`!asdict` on nested dataclasses::
378378

@@ -402,8 +402,8 @@ Module contents
402402

403403
Converts the dataclass *obj* to a tuple (by using the
404404
factory function *tuple_factory*). Each dataclass is converted
405-
to a tuple of its field values. dataclasses, dicts, lists, and
406-
tuples are recursed into. Other objects are copied with
405+
to a tuple of its field values. dataclasses, dicts, frozendicts, lists,
406+
and tuples are recursed into. Other objects are copied with
407407
:func:`copy.deepcopy`.
408408

409409
Continuing from the previous example::

Doc/library/itertools.rst

Lines changed: 66 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -833,6 +833,7 @@ and :term:`generators <generator>` which incur interpreter overhead.
833833
from collections import Counter, deque
834834
from contextlib import suppress
835835
from functools import reduce
836+
from heapq import heappush, heappushpop, heappush_max, heappushpop_max
836837
from math import comb, isqrt, prod, sumprod
837838
from operator import getitem, is_not, itemgetter, mul, neg, truediv
838839

@@ -848,11 +849,6 @@ and :term:`generators <generator>` which incur interpreter overhead.
848849
# prepend(1, [2, 3, 4]) → 1 2 3 4
849850
return chain([value], iterable)
850851

851-
def running_mean(iterable):
852-
"Yield the average of all values seen so far."
853-
# running_mean([8.5, 9.5, 7.5, 6.5]) → 8.5 9.0 8.5 8.0
854-
return map(truediv, accumulate(iterable), count(1))
855-
856852
def repeatfunc(function, times=None, *args):
857853
"Repeat calls to a function with specified arguments."
858854
if times is None:
@@ -1150,6 +1146,49 @@ and :term:`generators <generator>` which incur interpreter overhead.
11501146
return n
11511147

11521148

1149+
# ==== Running statistics ====
1150+
1151+
def running_mean(iterable):
1152+
"Average of values seen so far."
1153+
# running_mean([37, 33, 38, 28]) → 37 35 36 34
1154+
return map(truediv, accumulate(iterable), count(1))
1155+
1156+
def running_min(iterable):
1157+
"Smallest of values seen so far."
1158+
# running_min([37, 33, 38, 28]) → 37 33 33 28
1159+
return accumulate(iterable, func=min)
1160+
1161+
def running_max(iterable):
1162+
"Largest of values seen so far."
1163+
# running_max([37, 33, 38, 28]) → 37 37 38 38
1164+
return accumulate(iterable, func=max)
1165+
1166+
def running_median(iterable):
1167+
"Median of values seen so far."
1168+
# running_median([37, 33, 38, 28]) → 37 35 37 35
1169+
read = iter(iterable).__next__
1170+
lo = [] # max-heap
1171+
hi = [] # min-heap the same size as or one smaller than lo
1172+
with suppress(StopIteration):
1173+
while True:
1174+
heappush_max(lo, heappushpop(hi, read()))
1175+
yield lo[0]
1176+
heappush(hi, heappushpop_max(lo, read()))
1177+
yield (lo[0] + hi[0]) / 2
1178+
1179+
def running_statistics(iterable):
1180+
"Aggregate statistics for values seen so far."
1181+
# Generate tuples: (size, minimum, median, maximum, mean)
1182+
t0, t1, t2, t3 = tee(iterable, 4)
1183+
return zip(
1184+
count(1),
1185+
running_min(t0),
1186+
running_median(t1),
1187+
running_max(t2),
1188+
running_mean(t3),
1189+
)
1190+
1191+
11531192
.. doctest::
11541193
:hide:
11551194

@@ -1226,10 +1265,6 @@ and :term:`generators <generator>` which incur interpreter overhead.
12261265
[(0, 'a'), (1, 'b'), (2, 'c')]
12271266

12281267

1229-
>>> list(running_mean([8.5, 9.5, 7.5, 6.5]))
1230-
[8.5, 9.0, 8.5, 8.0]
1231-
1232-
12331268
>>> for _ in loops(5):
12341269
... print('hi')
12351270
...
@@ -1789,6 +1824,28 @@ and :term:`generators <generator>` which incur interpreter overhead.
17891824
True
17901825

17911826

1827+
>>> list(running_mean([8.5, 9.5, 7.5, 6.5]))
1828+
[8.5, 9.0, 8.5, 8.0]
1829+
>>> list(running_mean([37, 33, 38, 28]))
1830+
[37.0, 35.0, 36.0, 34.0]
1831+
1832+
1833+
>>> list(running_min([37, 33, 38, 28]))
1834+
[37, 33, 33, 28]
1835+
1836+
1837+
>>> list(running_max([37, 33, 38, 28]))
1838+
[37, 37, 38, 38]
1839+
1840+
1841+
>>> list(running_median([37, 33, 38, 28]))
1842+
[37, 35.0, 37, 35.0]
1843+
1844+
1845+
>>> list(running_statistics([37, 33, 38, 28]))
1846+
[(1, 37, 37, 37, 37.0), (2, 33, 35.0, 37, 35.0), (3, 33, 37, 38, 36.0), (4, 28, 35.0, 38, 34.0)]
1847+
1848+
17921849
.. testcode::
17931850
:hide:
17941851

Doc/library/re.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1953,7 +1953,7 @@ successive matches::
19531953

19541954
class Token(NamedTuple):
19551955
type: str
1956-
value: str
1956+
value: int | float | str
19571957
line: int
19581958
column: int
19591959

Doc/library/sys.monitoring.rst

Lines changed: 19 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -180,8 +180,8 @@ Local events
180180
''''''''''''
181181

182182
Local events are associated with normal execution of the program and happen
183-
at clearly defined locations. All local events can be disabled.
184-
The local events are:
183+
at clearly defined locations. All local events can be disabled
184+
per location. The local events are:
185185

186186
* :monitoring-event:`PY_START`
187187
* :monitoring-event:`PY_RESUME`
@@ -205,6 +205,8 @@ Using :monitoring-event:`BRANCH_LEFT` and :monitoring-event:`BRANCH_RIGHT`
205205
events will give much better performance as they can be disabled
206206
independently.
207207

208+
.. _monitoring-ancillary-events:
209+
208210
Ancillary events
209211
''''''''''''''''
210212

@@ -226,14 +228,20 @@ Other events
226228
''''''''''''
227229

228230
Other events are not necessarily tied to a specific location in the
229-
program and cannot be individually disabled via :data:`DISABLE`.
231+
program and cannot be individually disabled per location.
230232

231233
The other events that can be monitored are:
232234

233235
* :monitoring-event:`PY_THROW`
234236
* :monitoring-event:`PY_UNWIND`
235237
* :monitoring-event:`RAISE`
236238
* :monitoring-event:`EXCEPTION_HANDLED`
239+
* :monitoring-event:`RERAISE`
240+
241+
.. versionchanged:: 3.15
242+
Other events can now be turned on and disabled on a per code object
243+
basis. Returning :data:`DISABLE` from a callback disables the event
244+
for the entire code object (for the current tool).
237245

238246

239247
The STOP_ITERATION event
@@ -247,8 +255,7 @@ raise an exception unless it would be visible to other code.
247255

248256
To allow tools to monitor for real exceptions without slowing down generators
249257
and coroutines, the :monitoring-event:`STOP_ITERATION` event is provided.
250-
:monitoring-event:`STOP_ITERATION` can be locally disabled, unlike
251-
:monitoring-event:`RAISE`.
258+
:monitoring-event:`STOP_ITERATION` can be locally disabled.
252259

253260
Note that the :monitoring-event:`STOP_ITERATION` event and the
254261
:monitoring-event:`RAISE` event for a :exc:`StopIteration` exception are
@@ -314,15 +321,14 @@ location by returning :data:`sys.monitoring.DISABLE` from a callback function.
314321
This does not change which events are set, or any other code locations for the
315322
same event.
316323

317-
Disabling events for specific locations is very important for high
318-
performance monitoring. For example, a program can be run under a
319-
debugger with no overhead if the debugger disables all monitoring
320-
except for a few breakpoints.
324+
:ref:`Other events <monitoring-event-global>` can be disabled on a per code
325+
object basis by returning :data:`sys.monitoring.DISABLE` from a callback
326+
function. This disables the event for the entire code object (for the current
327+
tool).
321328

322-
If :data:`DISABLE` is returned by a callback for a
323-
:ref:`global event <monitoring-event-global>`, :exc:`ValueError` will be raised
324-
by the interpreter in a non-specific location (that is, no traceback will be
325-
provided).
329+
Disabling events for specific locations is very important for high performance
330+
monitoring. For example, a program can be run under a debugger with no overhead
331+
if the debugger disables all monitoring except for a few breakpoints.
326332

327333
.. function:: restart_events() -> None
328334

0 commit comments

Comments
 (0)