Skip to content

Commit f8c3bdd

Browse files
Merge branch 'main' into doc-fix-84116
2 parents 2325383 + 66e1399 commit f8c3bdd

Some content is hidden

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

43 files changed

+632
-279
lines changed

.github/CODEOWNERS

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -143,6 +143,9 @@ Misc/externals.spdx.json @sethmlarson
143143
Misc/sbom.spdx.json @sethmlarson
144144
Tools/build/generate_sbom.py @sethmlarson
145145

146+
# ABI check
147+
Misc/libabigail.abignore @encukou
148+
146149

147150
# ----------------------------------------------------------------------------
148151
# Platform Support

Doc/library/itertools.rst

Lines changed: 23 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -819,7 +819,7 @@ well as with the built-in itertools such as ``map()``, ``filter()``,
819819

820820
A secondary purpose of the recipes is to serve as an incubator. The
821821
``accumulate()``, ``compress()``, and ``pairwise()`` itertools started out as
822-
recipes. Currently, the ``sliding_window()``, ``iter_index()``, and ``sieve()``
822+
recipes. Currently, the ``sliding_window()``, ``derangements()``, and ``sieve()``
823823
recipes are being tested to see whether they prove their worth.
824824

825825
Substantially all of these recipes and many, many others can be installed from
@@ -838,11 +838,16 @@ and :term:`generators <generator>` which incur interpreter overhead.
838838

839839
.. testcode::
840840

841+
from itertools import (accumulate, batched, chain, combinations, compress,
842+
count, cycle, filterfalse, groupby, islice, permutations, product,
843+
repeat, starmap, tee, zip_longest)
841844
from collections import Counter, deque
842845
from contextlib import suppress
843846
from functools import reduce
844-
from math import comb, prod, sumprod, isqrt
845-
from operator import is_not, itemgetter, getitem, mul, neg
847+
from math import comb, isqrt, prod, sumprod
848+
from operator import getitem, is_not, itemgetter, mul, neg
849+
850+
# ==== Basic one liners ====
846851

847852
def take(n, iterable):
848853
"Return first n items of the iterable as a list."
@@ -899,15 +904,17 @@ and :term:`generators <generator>` which incur interpreter overhead.
899904

900905
def first_true(iterable, default=False, predicate=None):
901906
"Returns the first true value or the *default* if there is no true value."
902-
# first_true([a,b,c], x) → a or b or c or x
903-
# first_true([a,b], x, f) → a if f(a) else b if f(b) else x
907+
# first_true([a, b, c], x) → a or b or c or x
908+
# first_true([a, b], x, f) → a if f(a) else b if f(b) else x
904909
return next(filter(predicate, iterable), default)
905910

906911
def all_equal(iterable, key=None):
907912
"Returns True if all the elements are equal to each other."
908913
# all_equal('4٤௪౪໔', key=int) → True
909914
return len(take(2, groupby(iterable, key))) <= 1
910915

916+
# ==== Data pipelines ====
917+
911918
def unique_justseen(iterable, key=None):
912919
"Yield unique elements, preserving order. Remember only the element just seen."
913920
# unique_justseen('AAAABBBCCDAABBB') → A B C D A B
@@ -940,7 +947,7 @@ and :term:`generators <generator>` which incur interpreter overhead.
940947

941948
def sliding_window(iterable, n):
942949
"Collect data into overlapping fixed-length chunks or blocks."
943-
# sliding_window('ABCDEFG', 4) → ABCD BCDE CDEF DEFG
950+
# sliding_window('ABCDEFG', 3) → ABC BCD CDE DEF EFG
944951
iterator = iter(iterable)
945952
window = deque(islice(iterator, n - 1), maxlen=n)
946953
for x in iterator:
@@ -949,7 +956,7 @@ and :term:`generators <generator>` which incur interpreter overhead.
949956

950957
def grouper(iterable, n, *, incomplete='fill', fillvalue=None):
951958
"Collect data into non-overlapping fixed-length chunks or blocks."
952-
# grouper('ABCDEFG', 3, fillvalue='x') → ABC DEF Gxx
959+
# grouper('ABCDEFG', 3, fillvalue='x') → ABC DEF Gxx
953960
# grouper('ABCDEFG', 3, incomplete='strict') → ABC DEF ValueError
954961
# grouper('ABCDEFG', 3, incomplete='ignore') → ABC DEF
955962
iterators = [iter(iterable)] * n
@@ -1014,10 +1021,7 @@ and :term:`generators <generator>` which incur interpreter overhead.
10141021
while True:
10151022
yield function()
10161023

1017-
1018-
The following recipes have a more mathematical flavor:
1019-
1020-
.. testcode::
1024+
# ==== Mathematical operations ====
10211025

10221026
def multinomial(*counts):
10231027
"Number of distinct arrangements of a multiset."
@@ -1036,9 +1040,11 @@ The following recipes have a more mathematical flavor:
10361040
# sum_of_squares([10, 20, 30]) → 1400
10371041
return sumprod(*tee(iterable))
10381042
1043+
# ==== Matrix operations ====
1044+
10391045
def reshape(matrix, columns):
10401046
"Reshape a 2-D matrix to have a given number of columns."
1041-
# reshape([(0, 1), (2, 3), (4, 5)], 3) → (0, 1, 2), (3, 4, 5)
1047+
# reshape([(0, 1), (2, 3), (4, 5)], 3) → (0, 1, 2) (3, 4, 5)
10421048
return batched(chain.from_iterable(matrix), columns, strict=True)
10431049

10441050
def transpose(matrix):
@@ -1048,10 +1054,12 @@ The following recipes have a more mathematical flavor:
10481054
10491055
def matmul(m1, m2):
10501056
"Multiply two matrices."
1051-
# matmul([(7, 5), (3, 5)], [(2, 5), (7, 9)]) → (49, 80), (41, 60)
1057+
# matmul([(7, 5), (3, 5)], [(2, 5), (7, 9)]) → (49, 80) (41, 60)
10521058
n = len(m2[0])
10531059
return batched(starmap(sumprod, product(m1, transpose(m2))), n)
10541060

1061+
# ==== Polynomial arithmetic ====
1062+
10551063
def convolve(signal, kernel):
10561064
"""Discrete linear convolution of two iterables.
10571065
Equivalent to polynomial multiplication.
@@ -1106,6 +1114,8 @@ The following recipes have a more mathematical flavor:
11061114
powers = reversed(range(1, n))
11071115
return list(map(mul, coefficients, powers))
11081116

1117+
# ==== Number theory ====
1118+
11091119
def sieve(n):
11101120
"Primes less than n."
11111121
# sieve(30) → 2 3 5 7 11 13 17 19 23 29

Doc/library/readline.rst

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -403,3 +403,9 @@ support history save/restore. ::
403403
def save_history(self, histfile):
404404
readline.set_history_length(1000)
405405
readline.write_history_file(histfile)
406+
407+
.. note::
408+
409+
The new :term:`REPL` introduced in version 3.13 doesn't support readline.
410+
However, readline can still be used by setting the :envvar:`PYTHON_BASIC_REPL`
411+
environment variable.

Doc/library/stdtypes.rst

Lines changed: 103 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1441,6 +1441,109 @@ application).
14411441
list appear empty for the duration, and raises :exc:`ValueError` if it can
14421442
detect that the list has been mutated during a sort.
14431443

1444+
.. admonition:: Thread safety
1445+
1446+
Reading a single element from a :class:`list` is
1447+
:term:`atomic <atomic operation>`:
1448+
1449+
.. code-block::
1450+
:class: green
1451+
1452+
lst[i] # list.__getitem__
1453+
1454+
The following methods traverse the list and use :term:`atomic <atomic operation>`
1455+
reads of each item to perform their function. That means that they may
1456+
return results affected by concurrent modifications:
1457+
1458+
.. code-block::
1459+
:class: maybe
1460+
1461+
item in lst
1462+
lst.index(item)
1463+
lst.count(item)
1464+
1465+
All of the above methods/operations are also lock-free. They do not block
1466+
concurrent modifications. Other operations that hold a lock will not block
1467+
these from observing intermediate states.
1468+
1469+
All other operations from here on block using the per-object lock.
1470+
1471+
Writing a single item via ``lst[i] = x`` is safe to call from multiple
1472+
threads and will not corrupt the list.
1473+
1474+
The following operations return new objects and appear
1475+
:term:`atomic <atomic operation>` to other threads:
1476+
1477+
.. code-block::
1478+
:class: good
1479+
1480+
lst1 + lst2 # concatenates two lists into a new list
1481+
x * lst # repeats lst x times into a new list
1482+
lst.copy() # returns a shallow copy of the list
1483+
1484+
Methods that only operate on a single elements with no shifting required are
1485+
:term:`atomic <atomic operation>`:
1486+
1487+
.. code-block::
1488+
:class: good
1489+
1490+
lst.append(x) # append to the end of the list, no shifting required
1491+
lst.pop() # pop element from the end of the list, no shifting required
1492+
1493+
The :meth:`~list.clear` method is also :term:`atomic <atomic operation>`.
1494+
Other threads cannot observe elements being removed.
1495+
1496+
The :meth:`~list.sort` method is not :term:`atomic <atomic operation>`.
1497+
Other threads cannot observe intermediate states during sorting, but the
1498+
list appears empty for the duration of the sort.
1499+
1500+
The following operations may allow lock-free operations to observe
1501+
intermediate states since they modify multiple elements in place:
1502+
1503+
.. code-block::
1504+
:class: maybe
1505+
1506+
lst.insert(idx, item) # shifts elements
1507+
lst.pop(idx) # idx not at the end of the list, shifts elements
1508+
lst *= x # copies elements in place
1509+
1510+
The :meth:`~list.remove` method may allow concurrent modifications since
1511+
element comparison may execute arbitrary Python code (via
1512+
:meth:`~object.__eq__`).
1513+
1514+
:meth:`~list.extend` is safe to call from multiple threads. However, its
1515+
guarantees depend on the iterable passed to it. If it is a :class:`list`, a
1516+
:class:`tuple`, a :class:`set`, a :class:`frozenset`, a :class:`dict` or a
1517+
:ref:`dictionary view object <dict-views>` (but not their subclasses), the
1518+
``extend`` operation is safe from concurrent modifications to the iterable.
1519+
Otherwise, an iterator is created which can be concurrently modified by
1520+
another thread. The same applies to inplace concatenation of a list with
1521+
other iterables when using ``lst += iterable``.
1522+
1523+
Similarly, assigning to a list slice with ``lst[i:j] = iterable`` is safe
1524+
to call from multiple threads, but ``iterable`` is only locked when it is
1525+
also a :class:`list` (but not its subclasses).
1526+
1527+
Operations that involve multiple accesses, as well as iteration, are never
1528+
atomic. For example:
1529+
1530+
.. code-block::
1531+
:class: bad
1532+
1533+
# NOT atomic: read-modify-write
1534+
lst[i] = lst[i] + 1
1535+
1536+
# NOT atomic: check-then-act
1537+
if lst:
1538+
item = lst.pop()
1539+
1540+
# NOT thread-safe: iteration while modifying
1541+
for item in lst:
1542+
process(item) # another thread may modify lst
1543+
1544+
Consider external synchronization when sharing :class:`list` instances
1545+
across threads. See :ref:`freethreading-python-howto` for more information.
1546+
14441547

14451548
.. _typesseq-tuple:
14461549

Doc/tutorial/interpreter.rst

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -34,13 +34,13 @@ status. If that doesn't work, you can exit the interpreter by typing the
3434
following command: ``quit()``.
3535

3636
The interpreter's line-editing features include interactive editing, history
37-
substitution and code completion on systems that support the `GNU Readline
38-
<https://tiswww.case.edu/php/chet/readline/rltop.html>`_ library.
37+
substitution and code completion on most systems.
3938
Perhaps the quickest check to see whether command line editing is supported is
40-
typing :kbd:`Control-P` to the first Python prompt you get. If it beeps, you
41-
have command line editing; see Appendix :ref:`tut-interacting` for an
42-
introduction to the keys. If nothing appears to happen, or if ``^P`` is
43-
echoed, command line editing isn't available; you'll only be able to use
39+
typing a word in on the Python prompt, then pressing Left arrow (or :kbd:`Control-b`).
40+
If the cursor moves, you have command line editing; see Appendix
41+
:ref:`tut-interacting` for an introduction to the keys.
42+
If nothing appears to happen, or if a sequence like ``^[[D`` or ``^B`` appears,
43+
command line editing isn't available; you'll only be able to use
4444
backspace to remove characters from the current line.
4545

4646
The interpreter operates somewhat like the Unix shell: when called with standard

Include/internal/pycore_opcode_metadata.h

Lines changed: 6 additions & 6 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Include/internal/pycore_uop_ids.h

Lines changed: 3 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Include/internal/pycore_uop_metadata.h

Lines changed: 12 additions & 12 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Lib/idlelib/help.html

Lines changed: 7 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)