Skip to content

Commit 3334c14

Browse files
committed
Merge branch 'main' into use-stackrefs
2 parents ff9d044 + ad9d059 commit 3334c14

File tree

95 files changed

+2196
-520
lines changed

Some content is hidden

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

95 files changed

+2196
-520
lines changed

.github/workflows/build.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,7 @@ jobs:
120120
- name: Build CPython
121121
run: |
122122
make -j4 regen-all
123-
make regen-stdlib-module-names regen-sbom
123+
make regen-stdlib-module-names regen-sbom regen-unicodedata
124124
- name: Check for changes
125125
run: |
126126
git add -u

Doc/c-api/stable.rst

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ Limited C API
6666

6767
Python 3.2 introduced the *Limited API*, a subset of Python's C API.
6868
Extensions that only use the Limited API can be
69-
compiled once and work with multiple versions of Python.
69+
compiled once and be loaded on multiple versions of Python.
7070
Contents of the Limited API are :ref:`listed below <limited-api-list>`.
7171

7272
.. c:macro:: Py_LIMITED_API
@@ -76,7 +76,7 @@ Contents of the Limited API are :ref:`listed below <limited-api-list>`.
7676

7777
Define ``Py_LIMITED_API`` to the value of :c:macro:`PY_VERSION_HEX`
7878
corresponding to the lowest Python version your extension supports.
79-
The extension will work without recompilation with all Python 3 releases
79+
The extension will be ABI-compatible with all Python 3 releases
8080
from the specified one onward, and can use Limited API introduced up to that
8181
version.
8282

@@ -94,7 +94,15 @@ Stable ABI
9494
----------
9595

9696
To enable this, Python provides a *Stable ABI*: a set of symbols that will
97-
remain compatible across Python 3.x versions.
97+
remain ABI-compatible across Python 3.x versions.
98+
99+
.. note::
100+
101+
The Stable ABI prevents ABI issues, like linker errors due to missing
102+
symbols or data corruption due to changes in structure layouts or function
103+
signatures.
104+
However, other changes in Python can change the *behavior* of extensions.
105+
See Python's Backwards Compatibility Policy (:pep:`387`) for details.
98106

99107
The Stable ABI contains symbols exposed in the :ref:`Limited API
100108
<limited-c-api>`, but also other ones – for example, functions necessary to

Doc/howto/free-threading-extensions.rst

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -167,6 +167,8 @@ that return :term:`strong references <strong reference>`.
167167
+-----------------------------------+-----------------------------------+
168168
| :c:func:`PyImport_AddModule` | :c:func:`PyImport_AddModuleRef` |
169169
+-----------------------------------+-----------------------------------+
170+
| :c:func:`PyCell_GET` | :c:func:`PyCell_Get` |
171+
+-----------------------------------+-----------------------------------+
170172

171173
Not all APIs that return borrowed references are problematic. For
172174
example, :c:func:`PyTuple_GetItem` is safe because tuples are immutable.

Doc/howto/logging.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,7 @@ that; formatting options will also be explained later.
127127

128128
Notice that in this example, we use functions directly on the ``logging``
129129
module, like ``logging.debug``, rather than creating a logger and calling
130-
functions on it. These functions operation on the root logger, but can be useful
130+
functions on it. These functions operate on the root logger, but can be useful
131131
as they will call :func:`~logging.basicConfig` for you if it has not been called yet, like in
132132
this example. In larger programs you'll usually want to control the logging
133133
configuration explicitly however - so for that reason as well as others, it's

Doc/library/collections.rst

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -783,10 +783,10 @@ sequence of key-value pairs into a dictionary of lists:
783783

784784
When each key is encountered for the first time, it is not already in the
785785
mapping; so an entry is automatically created using the :attr:`~defaultdict.default_factory`
786-
function which returns an empty :class:`list`. The :meth:`list.append`
786+
function which returns an empty :class:`list`. The :meth:`!list.append`
787787
operation then attaches the value to the new list. When keys are encountered
788788
again, the look-up proceeds normally (returning the list for that key) and the
789-
:meth:`list.append` operation adds another value to the list. This technique is
789+
:meth:`!list.append` operation adds another value to the list. This technique is
790790
simpler and faster than an equivalent technique using :meth:`dict.setdefault`:
791791

792792
>>> d = {}

Doc/library/ctypes.rst

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1949,6 +1949,24 @@ Utility functions
19491949
It behaves similar to ``pointer(obj)``, but the construction is a lot faster.
19501950

19511951

1952+
.. function:: CopyComPointer(src, dst)
1953+
1954+
Copies a COM pointer from *src* to *dst* and returns the Windows specific
1955+
:c:type:`!HRESULT` value.
1956+
1957+
If *src* is not ``NULL``, its ``AddRef`` method is called, incrementing the
1958+
reference count.
1959+
1960+
In contrast, the reference count of *dst* will not be decremented before
1961+
assigning the new value. Unless *dst* is ``NULL``, the caller is responsible
1962+
for decrementing the reference count by calling its ``Release`` method when
1963+
necessary.
1964+
1965+
.. availability:: Windows
1966+
1967+
.. versionadded:: next
1968+
1969+
19521970
.. function:: cast(obj, type)
19531971

19541972
This function is similar to the cast operator in C. It returns a new instance

Doc/library/errno.rst

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -613,6 +613,13 @@ defined by the module. The specific list of defined symbols is available as
613613
No route to host
614614

615615

616+
.. data:: EHWPOISON
617+
618+
Memory page has hardware error.
619+
620+
.. versionadded:: next
621+
622+
616623
.. data:: EALREADY
617624

618625
Operation already in progress. This error is mapped to the

Doc/library/io.rst

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,12 @@ In-memory text streams are also available as :class:`StringIO` objects::
6464

6565
f = io.StringIO("some initial text data")
6666

67+
.. note::
68+
69+
When working with a non-blocking stream, be aware that read operations on text I/O objects
70+
might raise a :exc:`BlockingIOError` if the stream cannot perform the operation
71+
immediately.
72+
6773
The text stream API is described in detail in the documentation of
6874
:class:`TextIOBase`.
6975

@@ -770,6 +776,11 @@ than raw I/O does.
770776
Read and return *size* bytes, or if *size* is not given or negative, until
771777
EOF or if the read call would block in non-blocking mode.
772778

779+
.. note::
780+
781+
When the underlying raw stream is non-blocking, a :exc:`BlockingIOError`
782+
may be raised if a read operation cannot be completed immediately.
783+
773784
.. method:: read1(size=-1, /)
774785

775786
Read and return up to *size* bytes with only one call on the raw stream.
@@ -779,6 +790,10 @@ than raw I/O does.
779790
.. versionchanged:: 3.7
780791
The *size* argument is now optional.
781792

793+
.. note::
794+
795+
When the underlying raw stream is non-blocking, a :exc:`BlockingIOError`
796+
may be raised if a read operation cannot be completed immediately.
782797

783798
.. class:: BufferedWriter(raw, buffer_size=DEFAULT_BUFFER_SIZE)
784799

@@ -1007,6 +1022,11 @@ Text I/O
10071022
.. versionchanged:: 3.10
10081023
The *encoding* argument now supports the ``"locale"`` dummy encoding name.
10091024

1025+
.. note::
1026+
1027+
When the underlying raw stream is non-blocking, a :exc:`BlockingIOError`
1028+
may be raised if a read operation cannot be completed immediately.
1029+
10101030
:class:`TextIOWrapper` provides these data attributes and methods in
10111031
addition to those from :class:`TextIOBase` and :class:`IOBase`:
10121032

Doc/library/itertools.rst

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -877,6 +877,11 @@ and :term:`generators <generator>` which incur interpreter overhead.
877877
"Returns the sequence elements n times."
878878
return chain.from_iterable(repeat(tuple(iterable), n))
879879

880+
def loops(n):
881+
"Loop n times. Like range(n) but without creating integers."
882+
# for _ in loops(100): ...
883+
return repeat(None, n)
884+
880885
def tail(n, iterable):
881886
"Return an iterator over the last n items."
882887
# tail(3, 'ABCDEFG') → E F G
@@ -1099,6 +1104,11 @@ The following recipes have a more mathematical flavor:
10991104
data[p*p : n : p+p] = bytes(len(range(p*p, n, p+p)))
11001105
yield from iter_index(data, 1, start=3)
11011106

1107+
def is_prime(n):
1108+
"Return True if n is prime."
1109+
# is_prime(1_000_000_000_000_403) → True
1110+
return n > 1 and all(n % p for p in sieve(math.isqrt(n) + 1))
1111+
11021112
def factor(n):
11031113
"Prime factors of n."
11041114
# factor(99) → 3 3 11
@@ -1202,6 +1212,16 @@ The following recipes have a more mathematical flavor:
12021212
[0, 2, 4, 6]
12031213

12041214

1215+
>>> for _ in loops(5):
1216+
... print('hi')
1217+
...
1218+
hi
1219+
hi
1220+
hi
1221+
hi
1222+
hi
1223+
1224+
12051225
>>> list(tail(3, 'ABCDEFG'))
12061226
['E', 'F', 'G']
12071227
>>> # Verify the input is consumed greedily
@@ -1475,6 +1495,23 @@ The following recipes have a more mathematical flavor:
14751495
True
14761496

14771497

1498+
>>> small_primes = [2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47, 53, 59, 61, 67, 71, 73, 79, 83, 89, 97]
1499+
>>> list(filter(is_prime, range(-100, 100))) == small_primes
1500+
True
1501+
>>> carmichael = {561, 1105, 1729, 2465, 2821, 6601, 8911} # https://oeis.org/A002997
1502+
>>> any(map(is_prime, carmichael))
1503+
False
1504+
>>> # https://www.wolframalpha.com/input?i=is+128884753939+prime
1505+
>>> is_prime(128_884_753_939) # large prime
1506+
True
1507+
>>> is_prime(999953 * 999983) # large semiprime
1508+
False
1509+
>>> is_prime(1_000_000_000_000_007) # factor() example
1510+
False
1511+
>>> is_prime(1_000_000_000_000_403) # factor() example
1512+
True
1513+
1514+
14781515
>>> list(factor(99)) # Code example 1
14791516
[3, 3, 11]
14801517
>>> list(factor(1_000_000_000_000_007)) # Code example 2

Doc/library/traceback.rst

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -157,6 +157,13 @@ Module-Level Functions
157157
arguments have the same meaning as for :func:`print_stack`.
158158

159159

160+
.. function:: print_list(extracted_list, file=None)
161+
162+
Print the list of tuples as returned by :func:`extract_tb` or
163+
:func:`extract_stack` as a formatted stack trace to the given file.
164+
If *file* is ``None``, the output is written to :data:`sys.stderr`.
165+
166+
160167
.. function:: format_list(extracted_list)
161168

162169
Given a list of tuples or :class:`FrameSummary` objects as returned by

0 commit comments

Comments
 (0)