Skip to content

Commit 7cf7349

Browse files
authored
Merge branch 'main' into call-len
2 parents 0475b56 + b275b8f commit 7cf7349

File tree

134 files changed

+2249
-776
lines changed

Some content is hidden

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

134 files changed

+2249
-776
lines changed

.github/workflows/reusable-context.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,8 @@ jobs:
9797
run: python Tools/build/compute-changes.py
9898
env:
9999
GITHUB_DEFAULT_BRANCH: ${{ github.event.repository.default_branch }}
100+
CCF_TARGET_REF: ${{ github.base_ref || github.event.repository.default_branch }}
101+
CCF_HEAD_REF: ${{ github.event.pull_request.head.sha || github.sha }}
100102

101103
- name: Compute hash for config cache key
102104
id: config-hash

Doc/c-api/object.rst

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -737,3 +737,21 @@ Object Protocol
737737
caller must hold a :term:`strong reference` to *obj* when calling this.
738738
739739
.. versionadded:: 3.14
740+
741+
.. c:function:: int PyUnstable_Object_IsUniquelyReferenced(PyObject *op)
742+
743+
Determine if *op* only has one reference.
744+
745+
On GIL-enabled builds, this function is equivalent to
746+
:c:expr:`Py_REFCNT(op) == 1`.
747+
748+
On a :term:`free threaded <free threading>` build, this checks if *op*'s
749+
:term:`reference count` is equal to one and additionally checks if *op*
750+
is only used by this thread. :c:expr:`Py_REFCNT(op) == 1` is **not**
751+
thread-safe on free threaded builds; prefer this function.
752+
753+
The caller must hold an :term:`attached thread state`, despite the fact
754+
that this function doesn't call into the Python interpreter. This function
755+
cannot fail.
756+
757+
.. versionadded:: 3.14

Doc/c-api/refcounting.rst

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,14 @@ of Python objects.
2323
2424
Use the :c:func:`Py_SET_REFCNT()` function to set an object reference count.
2525
26-
See also the function :c:func:`PyUnstable_Object_IsUniqueReferencedTemporary()`.
26+
.. note::
27+
28+
On :term:`free threaded <free threading>` builds of Python, returning 1
29+
isn't sufficient to determine if it's safe to treat *o* as having no
30+
access by other threads. Use :c:func:`PyUnstable_Object_IsUniquelyReferenced`
31+
for that instead.
32+
33+
See also the function :c:func:`PyUnstable_Object_IsUniqueReferencedTemporary()`.
2734
2835
.. versionchanged:: 3.10
2936
:c:func:`Py_REFCNT()` is changed to the inline static function.

Doc/deprecations/index.rst

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@ Deprecations
77

88
.. include:: pending-removal-in-3.17.rst
99

10+
.. include:: pending-removal-in-3.19.rst
11+
1012
.. include:: pending-removal-in-future.rst
1113

1214
C API deprecations
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
Pending removal in Python 3.19
2+
------------------------------
3+
4+
* :mod:`ctypes`:
5+
6+
* Implicitly switching to the MSVC-compatible struct layout by setting
7+
:attr:`~ctypes.Structure._pack_` but not :attr:`~ctypes.Structure._layout_`
8+
on non-Windows platforms.

Doc/library/ast.rst

Lines changed: 28 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
:mod:`!ast` --- Abstract Syntax Trees
1+
:mod:`!ast` --- Abstract syntax trees
22
=====================================
33

44
.. module:: ast
@@ -29,7 +29,7 @@ compiled into a Python code object using the built-in :func:`compile` function.
2929

3030
.. _abstract-grammar:
3131

32-
Abstract Grammar
32+
Abstract grammar
3333
----------------
3434

3535
The abstract grammar is currently defined as follows:
@@ -2156,10 +2156,10 @@ Async and await
21562156
of :class:`ast.operator`, :class:`ast.unaryop`, :class:`ast.cmpop`,
21572157
:class:`ast.boolop` and :class:`ast.expr_context`) on the returned tree
21582158
will be singletons. Changes to one will be reflected in all other
2159-
occurrences of the same value (e.g. :class:`ast.Add`).
2159+
occurrences of the same value (for example, :class:`ast.Add`).
21602160

21612161

2162-
:mod:`ast` Helpers
2162+
:mod:`ast` helpers
21632163
------------------
21642164

21652165
Apart from the node classes, the :mod:`ast` module defines these utility functions
@@ -2484,7 +2484,7 @@ and classes for traversing abstract syntax trees:
24842484

24852485
.. _ast-compiler-flags:
24862486

2487-
Compiler Flags
2487+
Compiler flags
24882488
--------------
24892489

24902490
The following flags may be passed to :func:`compile` in order to change
@@ -2533,7 +2533,7 @@ effects on the compilation of a program:
25332533

25342534
.. _ast-cli:
25352535

2536-
Command-Line Usage
2536+
Command-line usage
25372537
------------------
25382538

25392539
.. versionadded:: 3.9
@@ -2572,6 +2572,28 @@ The following options are accepted:
25722572

25732573
Indentation of nodes in AST (number of spaces).
25742574

2575+
.. option:: --feature-version <version>
2576+
2577+
Python version in the format 3.x (for example, 3.10). Defaults to the
2578+
current version of the interpreter.
2579+
2580+
.. versionadded:: next
2581+
2582+
.. option:: -O <level>
2583+
--optimize <level>
2584+
2585+
Optimization level for parser. Defaults to no optimization.
2586+
2587+
.. versionadded:: next
2588+
2589+
.. option:: --show-empty
2590+
2591+
Show empty lists and fields that are ``None``. Defaults to not showing empty
2592+
objects.
2593+
2594+
.. versionadded:: next
2595+
2596+
25752597
If :file:`infile` is specified its contents are parsed to AST and dumped
25762598
to stdout. Otherwise, the content is read from stdin.
25772599

Doc/library/ctypes.rst

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2754,6 +2754,16 @@ fields, or any other data types containing pointer type fields.
27542754
when :attr:`_fields_` is assigned, otherwise it will have no effect.
27552755
Setting this attribute to 0 is the same as not setting it at all.
27562756

2757+
This is only implemented for the MSVC-compatible memory layout.
2758+
2759+
.. deprecated-removed:: next 3.19
2760+
2761+
For historical reasons, if :attr:`!_pack_` is non-zero,
2762+
the MSVC-compatible layout will be used by default.
2763+
On non-Windows platforms, this default is deprecated and is slated to
2764+
become an error in Python 3.19.
2765+
If it is intended, set :attr:`~Structure._layout_` to ``'ms'``
2766+
explicitly.
27572767

27582768
.. attribute:: _align_
27592769

@@ -2782,12 +2792,15 @@ fields, or any other data types containing pointer type fields.
27822792
Currently the default will be:
27832793

27842794
- On Windows: ``"ms"``
2785-
- When :attr:`~Structure._pack_` is specified: ``"ms"``
2795+
- When :attr:`~Structure._pack_` is specified: ``"ms"``.
2796+
(This is deprecated; see :attr:`~Structure._pack_` documentation.)
27862797
- Otherwise: ``"gcc-sysv"``
27872798

27882799
:attr:`!_layout_` must already be defined when
27892800
:attr:`~Structure._fields_` is assigned, otherwise it will have no effect.
27902801

2802+
.. versionadded:: next
2803+
27912804
.. attribute:: _anonymous_
27922805

27932806
An optional sequence that lists the names of unnamed (anonymous) fields.

Doc/library/gc.rst

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -128,6 +128,11 @@ The :mod:`gc` module provides the following functions:
128128
starts. For each collection, all the objects in the young generation and some
129129
fraction of the old generation is collected.
130130

131+
In the free-threaded build, the increase in process resident set size (RSS)
132+
is also checked before running the collector. If the RSS has not increased
133+
by 10% since the last collection and the net number of object allocations
134+
has not exceeded 40 times *threshold0*, the collection is not run.
135+
131136
The fraction of the old generation that is collected is **inversely** proportional
132137
to *threshold1*. The larger *threshold1* is, the slower objects in the old generation
133138
are collected.

Doc/library/heapq.rst

Lines changed: 88 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -16,40 +16,56 @@
1616
This module provides an implementation of the heap queue algorithm, also known
1717
as the priority queue algorithm.
1818

19-
Heaps are binary trees for which every parent node has a value less than or
20-
equal to any of its children. We refer to this condition as the heap invariant.
19+
Min-heaps are binary trees for which every parent node has a value less than
20+
or equal to any of its children.
21+
We refer to this condition as the heap invariant.
2122

22-
This implementation uses arrays for which
23-
``heap[k] <= heap[2*k+1]`` and ``heap[k] <= heap[2*k+2]`` for all *k*, counting
24-
elements from zero. For the sake of comparison, non-existing elements are
25-
considered to be infinite. The interesting property of a heap is that its
26-
smallest element is always the root, ``heap[0]``.
23+
For min-heaps, this implementation uses lists for which
24+
``heap[k] <= heap[2*k+1]`` and ``heap[k] <= heap[2*k+2]`` for all *k* for which
25+
the compared elements exist. Elements are counted from zero. The interesting
26+
property of a min-heap is that its smallest element is always the root,
27+
``heap[0]``.
2728

28-
The API below differs from textbook heap algorithms in two aspects: (a) We use
29-
zero-based indexing. This makes the relationship between the index for a node
30-
and the indexes for its children slightly less obvious, but is more suitable
31-
since Python uses zero-based indexing. (b) Our pop method returns the smallest
32-
item, not the largest (called a "min heap" in textbooks; a "max heap" is more
33-
common in texts because of its suitability for in-place sorting).
29+
Max-heaps satisfy the reverse invariant: every parent node has a value
30+
*greater* than any of its children. These are implemented as lists for which
31+
``maxheap[2*k+1] <= maxheap[k]`` and ``maxheap[2*k+2] <= maxheap[k]`` for all
32+
*k* for which the compared elements exist.
33+
The root, ``maxheap[0]``, contains the *largest* element;
34+
``heap.sort(reverse=True)`` maintains the max-heap invariant.
3435

35-
These two make it possible to view the heap as a regular Python list without
36-
surprises: ``heap[0]`` is the smallest item, and ``heap.sort()`` maintains the
37-
heap invariant!
36+
The :mod:`!heapq` API differs from textbook heap algorithms in two aspects: (a)
37+
We use zero-based indexing. This makes the relationship between the index for
38+
a node and the indexes for its children slightly less obvious, but is more
39+
suitable since Python uses zero-based indexing. (b) Textbooks often focus on
40+
max-heaps, due to their suitability for in-place sorting. Our implementation
41+
favors min-heaps as they better correspond to Python :class:`lists <list>`.
3842

39-
To create a heap, use a list initialized to ``[]``, or you can transform a
40-
populated list into a heap via function :func:`heapify`.
43+
These two aspects make it possible to view the heap as a regular Python list
44+
without surprises: ``heap[0]`` is the smallest item, and ``heap.sort()``
45+
maintains the heap invariant!
4146

42-
The following functions are provided:
47+
Like :meth:`list.sort`, this implementation uses only the ``<`` operator
48+
for comparisons, for both min-heaps and max-heaps.
49+
50+
In the API below, and in this documentation, the unqualified term *heap*
51+
generally refers to a min-heap.
52+
The API for max-heaps is named using a ``_max`` suffix.
53+
54+
To create a heap, use a list initialized as ``[]``, or transform an existing list
55+
into a min-heap or max-heap using the :func:`heapify` or :func:`heapify_max`
56+
functions, respectively.
57+
58+
The following functions are provided for min-heaps:
4359

4460

4561
.. function:: heappush(heap, item)
4662

47-
Push the value *item* onto the *heap*, maintaining the heap invariant.
63+
Push the value *item* onto the *heap*, maintaining the min-heap invariant.
4864

4965

5066
.. function:: heappop(heap)
5167

52-
Pop and return the smallest item from the *heap*, maintaining the heap
68+
Pop and return the smallest item from the *heap*, maintaining the min-heap
5369
invariant. If the heap is empty, :exc:`IndexError` is raised. To access the
5470
smallest item without popping it, use ``heap[0]``.
5571

@@ -63,7 +79,7 @@ The following functions are provided:
6379

6480
.. function:: heapify(x)
6581

66-
Transform list *x* into a heap, in-place, in linear time.
82+
Transform list *x* into a min-heap, in-place, in linear time.
6783

6884

6985
.. function:: heapreplace(heap, item)
@@ -82,6 +98,56 @@ The following functions are provided:
8298
on the heap.
8399

84100

101+
For max-heaps, the following functions are provided:
102+
103+
104+
.. function:: heapify_max(x)
105+
106+
Transform list *x* into a max-heap, in-place, in linear time.
107+
108+
.. versionadded:: next
109+
110+
111+
.. function:: heappush_max(heap, item)
112+
113+
Push the value *item* onto the max-heap *heap*, maintaining the max-heap
114+
invariant.
115+
116+
.. versionadded:: next
117+
118+
119+
.. function:: heappop_max(heap)
120+
121+
Pop and return the largest item from the max-heap *heap*, maintaining the
122+
max-heap invariant. If the max-heap is empty, :exc:`IndexError` is raised.
123+
To access the largest item without popping it, use ``maxheap[0]``.
124+
125+
.. versionadded:: next
126+
127+
128+
.. function:: heappushpop_max(heap, item)
129+
130+
Push *item* on the max-heap *heap*, then pop and return the largest item
131+
from *heap*.
132+
The combined action runs more efficiently than :func:`heappush_max`
133+
followed by a separate call to :func:`heappop_max`.
134+
135+
.. versionadded:: next
136+
137+
138+
.. function:: heapreplace_max(heap, item)
139+
140+
Pop and return the largest item from the max-heap *heap* and also push the
141+
new *item*.
142+
The max-heap size doesn't change. If the max-heap is empty,
143+
:exc:`IndexError` is raised.
144+
145+
The value returned may be smaller than the *item* added. Refer to the
146+
analogous function :func:`heapreplace` for detailed usage notes.
147+
148+
.. versionadded:: next
149+
150+
85151
The module also offers three general purpose functions based on heaps.
86152

87153

Doc/library/pathlib.rst

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -872,10 +872,10 @@ conforming to :rfc:`8089`.
872872
.. versionadded:: 3.13
873873

874874
.. versionchanged:: next
875-
If a URL authority (e.g. a hostname) is present and resolves to a local
876-
address, it is discarded. If an authority is present and *doesn't*
877-
resolve to a local address, then on Windows a UNC path is returned (as
878-
before), and on other platforms a :exc:`ValueError` is raised.
875+
The URL authority is discarded if it matches the local hostname.
876+
Otherwise, if the authority isn't empty or ``localhost``, then on
877+
Windows a UNC path is returned (as before), and on other platforms a
878+
:exc:`ValueError` is raised.
879879

880880

881881
.. method:: Path.as_uri()

0 commit comments

Comments
 (0)