Skip to content

Commit 8ce4b53

Browse files
authored
Merge branch 'main' into jit-tracer-fitness
2 parents f2bde9e + ab41a34 commit 8ce4b53

44 files changed

Lines changed: 786 additions & 471 deletions

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/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/typing.rst

Lines changed: 62 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1174,7 +1174,8 @@ These can be used as types in annotations. They all support subscription using
11741174
or transforms parameters of another
11751175
callable. Usage is in the form
11761176
``Concatenate[Arg1Type, Arg2Type, ..., ParamSpecVariable]``. ``Concatenate``
1177-
is currently only valid when used as the first argument to a :ref:`Callable <annotating-callables>`.
1177+
is valid when used in :ref:`Callable <annotating-callables>` type hints
1178+
and when instantiating user-defined generic classes with :class:`ParamSpec` parameters.
11781179
The last parameter to ``Concatenate`` must be a :class:`ParamSpec` or
11791180
ellipsis (``...``).
11801181

@@ -1980,7 +1981,7 @@ without the dedicated syntax, as documented below.
19801981

19811982
.. _typevartuple:
19821983

1983-
.. class:: TypeVarTuple(name, *, default=typing.NoDefault)
1984+
.. class:: TypeVarTuple(name, *, bound=None, covariant=False, contravariant=False, infer_variance=False, default=typing.NoDefault)
19841985

19851986
Type variable tuple. A specialized form of :ref:`type variable <typevar>`
19861987
that enables *variadic* generics.
@@ -2090,6 +2091,24 @@ without the dedicated syntax, as documented below.
20902091

20912092
The name of the type variable tuple.
20922093

2094+
.. attribute:: __covariant__
2095+
2096+
Whether the type variable tuple has been explicitly marked as covariant.
2097+
2098+
.. versionadded:: 3.15
2099+
2100+
.. attribute:: __contravariant__
2101+
2102+
Whether the type variable tuple has been explicitly marked as contravariant.
2103+
2104+
.. versionadded:: 3.15
2105+
2106+
.. attribute:: __infer_variance__
2107+
2108+
Whether the type variable tuple's variance should be inferred by type checkers.
2109+
2110+
.. versionadded:: 3.15
2111+
20932112
.. attribute:: __default__
20942113

20952114
The default value of the type variable tuple, or :data:`typing.NoDefault` if it
@@ -2116,6 +2135,11 @@ without the dedicated syntax, as documented below.
21162135

21172136
.. versionadded:: 3.13
21182137

2138+
Type variable tuples created with ``covariant=True`` or
2139+
``contravariant=True`` can be used to declare covariant or contravariant
2140+
generic types. The ``bound`` argument is also accepted, similar to
2141+
:class:`TypeVar`, but its actual semantics are yet to be decided.
2142+
21192143
.. versionadded:: 3.11
21202144

21212145
.. versionchanged:: 3.12
@@ -2127,6 +2151,11 @@ without the dedicated syntax, as documented below.
21272151

21282152
Support for default values was added.
21292153

2154+
.. versionchanged:: 3.15
2155+
2156+
Added support for the ``bound``, ``covariant``, ``contravariant``, and
2157+
``infer_variance`` parameters.
2158+
21302159
.. class:: ParamSpec(name, *, bound=None, covariant=False, contravariant=False, default=typing.NoDefault)
21312160

21322161
Parameter specification variable. A specialized version of
@@ -2196,6 +2225,20 @@ without the dedicated syntax, as documented below.
21962225

21972226
The name of the parameter specification.
21982227

2228+
.. attribute:: __covariant__
2229+
2230+
Whether the parameter specification has been explicitly marked as covariant.
2231+
2232+
.. attribute:: __contravariant__
2233+
2234+
Whether the parameter specification has been explicitly marked as contravariant.
2235+
2236+
.. attribute:: __infer_variance__
2237+
2238+
Whether the parameter specification's variance should be inferred by type checkers.
2239+
2240+
.. versionadded:: 3.12
2241+
21992242
.. attribute:: __default__
22002243

22012244
The default value of the parameter specification, or :data:`typing.NoDefault` if it
@@ -3410,13 +3453,13 @@ Functions and decorators
34103453
Introspection helpers
34113454
---------------------
34123455

3413-
.. function:: get_type_hints(obj, globalns=None, localns=None, include_extras=False)
3456+
.. function:: get_type_hints(obj, globalns=None, localns=None, include_extras=False, *, format=Format.VALUE)
34143457

34153458
Return a dictionary containing type hints for a function, method, module,
34163459
class object, or other callable object.
34173460

3418-
This is often the same as ``obj.__annotations__``, but this function makes
3419-
the following changes to the annotations dictionary:
3461+
This is often the same as :func:`annotationlib.get_annotations`, but this
3462+
function makes the following changes to the annotations dictionary:
34203463

34213464
* Forward references encoded as string literals or :class:`ForwardRef`
34223465
objects are handled by evaluating them in *globalns*, *localns*, and
@@ -3430,29 +3473,28 @@ Introspection helpers
34303473
annotations from ``C``'s base classes with those on ``C`` directly. This
34313474
is done by traversing :attr:`C.__mro__ <type.__mro__>` and iteratively
34323475
combining
3433-
``__annotations__`` dictionaries. Annotations on classes appearing
3434-
earlier in the :term:`method resolution order` always take precedence over
3435-
annotations on classes appearing later in the method resolution order.
3476+
:term:`annotations <variable annotation>` of each base class. Annotations
3477+
on classes appearing earlier in the :term:`method resolution order` always
3478+
take precedence over annotations on classes appearing later in the method
3479+
resolution order.
34363480
* The function recursively replaces all occurrences of
34373481
``Annotated[T, ...]``, ``Required[T]``, ``NotRequired[T]``, and ``ReadOnly[T]``
34383482
with ``T``, unless *include_extras* is set to ``True`` (see
34393483
:class:`Annotated` for more information).
34403484

3441-
See also :func:`annotationlib.get_annotations`, a lower-level function that
3442-
returns annotations more directly.
3443-
34443485
.. caution::
34453486

34463487
This function may execute arbitrary code contained in annotations.
34473488
See :ref:`annotationlib-security` for more information.
34483489

34493490
.. note::
34503491

3451-
If any forward references in the annotations of *obj* are not resolvable
3452-
or are not valid Python code, this function will raise an exception
3453-
such as :exc:`NameError`. For example, this can happen with imported
3454-
:ref:`type aliases <type-aliases>` that include forward references,
3455-
or with names imported under :data:`if TYPE_CHECKING <TYPE_CHECKING>`.
3492+
If :attr:`Format.VALUE <annotationlib.Format.VALUE>` is used and any
3493+
forward references in the annotations of *obj* are not resolvable, a
3494+
:exc:`NameError` exception is raised. For example, this can happen
3495+
with names imported under :data:`if TYPE_CHECKING <TYPE_CHECKING>`.
3496+
More generally, any kind of exception can be raised if an annotation
3497+
contains invalid Python code.
34563498

34573499
.. note::
34583500

@@ -3470,6 +3512,10 @@ Introspection helpers
34703512
if a default value equal to ``None`` was set.
34713513
Now the annotation is returned unchanged.
34723514

3515+
.. versionchanged:: 3.14
3516+
Added the ``format`` parameter. See the documentation on
3517+
:func:`annotationlib.get_annotations` for more information.
3518+
34733519
.. versionchanged:: 3.14
34743520
Calling :func:`get_type_hints` on instances is no longer supported.
34753521
Some instances were accepted in earlier versions as an undocumented

Doc/whatsnew/3.15.rst

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1296,6 +1296,11 @@ typing
12961296
child classes of that class cannot inherit from other disjoint bases that are
12971297
not parent or child classes of ``C``. (Contributed by Jelle Zijlstra in :gh:`148639`.)
12981298

1299+
* :class:`~typing.TypeVarTuple` now accepts ``bound``, ``covariant``,
1300+
``contravariant``, and ``infer_variance`` keyword arguments, matching the
1301+
interface of :class:`~typing.TypeVar` and :class:`~typing.ParamSpec`.
1302+
``bound`` semantics remain undefined in the specification.
1303+
12991304

13001305
unicodedata
13011306
-----------

Include/Python.h

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,11 @@
99
// is not needed.
1010

1111

12-
// Include Python header files
13-
#include "patchlevel.h"
14-
#include "pyconfig.h"
15-
#include "pymacconfig.h"
12+
// Include Python configuration headers
13+
#include "patchlevel.h" // the Python version
14+
#include "pyconfig.h" // information from configure
15+
#include "pymacconfig.h" // overrides for pyconfig
16+
#include "pyabi.h" // feature/ABI selection
1617

1718

1819
// Include standard header files
@@ -46,13 +47,11 @@
4647
# endif
4748
#endif
4849

49-
#if defined(Py_GIL_DISABLED)
50-
# if defined(_MSC_VER)
51-
# include <intrin.h> // __readgsqword()
52-
# endif
53-
54-
# if defined(__MINGW32__)
55-
# include <intrin.h> // __readgsqword()
50+
#if !defined(Py_LIMITED_API)
51+
# if defined(Py_GIL_DISABLED)
52+
# if defined(_MSC_VER) || defined(__MINGW32__)
53+
# include <intrin.h> // __readgsqword()
54+
# endif
5655
# endif
5756
#endif // Py_GIL_DISABLED
5857

@@ -67,6 +66,7 @@ __pragma(warning(disable: 4201))
6766

6867
// Include Python header files
6968
#include "pyport.h"
69+
#include "exports.h"
7070
#include "pymacro.h"
7171
#include "pymath.h"
7272
#include "pymem.h"

0 commit comments

Comments
 (0)