Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 497c8aa

Browse files
committed
Merge remote-tracking branch 'upstream/main' into resolve-exceptions-upfront
2 parents d5ab812 + 558768f commit 497c8aa

File tree

64 files changed

+28553
-27712
lines changed

Some content is hidden

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

64 files changed

+28553
-27712
lines changed

Doc/c-api/code.rst

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
.. highlight:: c
22

3-
.. _codeobjects:
4-
53
.. index:: object; code, code object
64

5+
.. _codeobjects:
6+
77
Code Objects
88
------------
99

Doc/c-api/function.rst

+9
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,15 @@ There are a few functions specific to Python functions.
8383
Raises :exc:`SystemError` and returns ``-1`` on failure.
8484
8585
86+
.. c:function:: void PyFunction_SetVectorcall(PyFunctionObject *func, vectorcallfunc vectorcall)
87+
88+
Set the vectorcall field of a given function object *func*.
89+
90+
Warning: extensions using this API must preserve the behavior
91+
of the unaltered (default) vectorcall function!
92+
93+
.. versionadded:: 3.12
94+
8695
.. c:function:: PyObject* PyFunction_GetClosure(PyObject *op)
8796
8897
Return the closure associated with the function object *op*. This can be ``NULL``

Doc/faq/programming.rst

+2
Original file line numberDiff line numberDiff line change
@@ -1897,6 +1897,8 @@ The classes can be used like this:
18971897
'blog-why-python-rocks'
18981898

18991899

1900+
.. _faq-cache-method-calls:
1901+
19001902
How do I cache method calls?
19011903
----------------------------
19021904

Doc/library/argparse.rst

+20-1
Original file line numberDiff line numberDiff line change
@@ -2031,7 +2031,26 @@ Mutual exclusion
20312031

20322032
Note that currently mutually exclusive argument groups do not support the
20332033
*title* and *description* arguments of
2034-
:meth:`~ArgumentParser.add_argument_group`.
2034+
:meth:`~ArgumentParser.add_argument_group`. However, a mutually exclusive
2035+
group can be added to an argument group that has a title and description.
2036+
For example::
2037+
2038+
>>> parser = argparse.ArgumentParser(prog='PROG')
2039+
>>> group = parser.add_argument_group('Group title', 'Group description')
2040+
>>> exclusive_group = group.add_mutually_exclusive_group(required=True)
2041+
>>> exclusive_group.add_argument('--foo', help='foo help')
2042+
>>> exclusive_group.add_argument('--bar', help='bar help')
2043+
>>> parser.print_help()
2044+
usage: PROG [-h] (--foo FOO | --bar BAR)
2045+
2046+
options:
2047+
-h, --help show this help message and exit
2048+
2049+
Group title:
2050+
Group description
2051+
2052+
--foo FOO foo help
2053+
--bar BAR bar help
20352054

20362055
.. versionchanged:: 3.11
20372056
Calling :meth:`add_argument_group` or :meth:`add_mutually_exclusive_group`

Doc/library/functools.rst

+3
Original file line numberDiff line numberDiff line change
@@ -197,6 +197,9 @@ The :mod:`functools` module defines the following functions:
197197
The cache keeps references to the arguments and return values until they age
198198
out of the cache or until the cache is cleared.
199199

200+
If a method is cached, the `self` instance argument is included in the
201+
cache. See :ref:`faq-cache-method-calls`
202+
200203
An `LRU (least recently used) cache
201204
<https://en.wikipedia.org/wiki/Cache_replacement_policies#Least_recently_used_(LRU)>`_
202205
works best when the most recent calls are the best predictors of upcoming

Doc/library/itertools.rst

+34-6
Original file line numberDiff line numberDiff line change
@@ -314,7 +314,7 @@ loops that truncate the stream.
314314

315315
def count(start=0, step=1):
316316
# count(10) --> 10 11 12 13 14 ...
317-
# count(2.5, 0.5) -> 2.5 3.0 3.5 ...
317+
# count(2.5, 0.5) --> 2.5 3.0 3.5 ...
318318
n = start
319319
while True:
320320
yield n
@@ -739,7 +739,7 @@ which incur interpreter overhead.
739739

740740
def prepend(value, iterator):
741741
"Prepend a single value in front of an iterator"
742-
# prepend(1, [2, 3, 4]) -> 1 2 3 4
742+
# prepend(1, [2, 3, 4]) --> 1 2 3 4
743743
return chain([value], iterator)
744744

745745
def tabulate(function, start=0):
@@ -812,6 +812,16 @@ which incur interpreter overhead.
812812
for k in range(len(roots) + 1)
813813
]
814814

815+
def sieve(n):
816+
"Primes less than n"
817+
# sieve(30) --> 2 3 5 7 11 13 17 19 23 29
818+
data = bytearray([1]) * n
819+
data[:2] = 0, 0
820+
limit = math.isqrt(n) + 1
821+
for p in compress(range(limit), data):
822+
data[p+p : n : p] = bytearray(len(range(p+p, n, p)))
823+
return compress(count(), data)
824+
815825
def flatten(list_of_lists):
816826
"Flatten one level of nesting"
817827
return chain.from_iterable(list_of_lists)
@@ -842,12 +852,12 @@ which incur interpreter overhead.
842852
843853
def triplewise(iterable):
844854
"Return overlapping triplets from an iterable"
845-
# triplewise('ABCDEFG') -> ABC BCD CDE DEF EFG
855+
# triplewise('ABCDEFG') --> ABC BCD CDE DEF EFG
846856
for (a, _), (b, c) in pairwise(pairwise(iterable)):
847857
yield a, b, c
848858

849859
def sliding_window(iterable, n):
850-
# sliding_window('ABCDEFG', 4) -> ABCD BCDE CDEF DEFG
860+
# sliding_window('ABCDEFG', 4) --> ABCD BCDE CDEF DEFG
851861
it = iter(iterable)
852862
window = collections.deque(islice(it, n), maxlen=n)
853863
if len(window) == n:
@@ -1079,6 +1089,7 @@ which incur interpreter overhead.
10791089
>>> import operator
10801090
>>> import collections
10811091
>>> import math
1092+
>>> import random
10821093

10831094
>>> take(10, count())
10841095
[0, 1, 2, 3, 4, 5, 6, 7, 8, 9]
@@ -1128,7 +1139,6 @@ which incur interpreter overhead.
11281139
>>> list(repeatfunc(pow, 5, 2, 3))
11291140
[8, 8, 8, 8, 8]
11301141

1131-
>>> import random
11321142
>>> take(5, map(int, repeatfunc(random.random)))
11331143
[0, 0, 0, 0, 0]
11341144

@@ -1156,10 +1166,28 @@ which incur interpreter overhead.
11561166
>>> all(factored(x) == expanded(x) for x in range(-10, 11))
11571167
True
11581168

1169+
>>> list(sieve(30))
1170+
[2, 3, 5, 7, 11, 13, 17, 19, 23, 29]
1171+
>>> small_primes = [2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47, 53, 59]
1172+
>>> all(list(sieve(n)) == [p for p in small_primes if p < n] for n in range(60))
1173+
True
1174+
>>> len(list(sieve(100)))
1175+
25
1176+
>>> len(list(sieve(1_000)))
1177+
168
1178+
>>> len(list(sieve(10_000)))
1179+
1229
1180+
>>> len(list(sieve(100_000)))
1181+
9592
1182+
>>> len(list(sieve(1_000_000)))
1183+
78498
1184+
>>> carmichael = {561, 1105, 1729, 2465, 2821, 6601, 8911} # https://oeis.org/A002997
1185+
>>> set(sieve(10_000)).isdisjoint(carmichael)
1186+
True
1187+
11591188
>>> list(flatten([('a', 'b'), (), ('c', 'd', 'e'), ('f',), ('g', 'h', 'i')]))
11601189
['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i']
11611190

1162-
>>> import random
11631191
>>> random.seed(85753098575309)
11641192
>>> list(repeatfunc(random.random, 3))
11651193
[0.16370491282496968, 0.45889608687313455, 0.3747076837820118]

Doc/library/math.rst

+2-2
Original file line numberDiff line numberDiff line change
@@ -45,8 +45,8 @@ Number-theoretic and representation functions
4545
to zero when ``k > n``.
4646

4747
Also called the binomial coefficient because it is equivalent
48-
to the coefficient of k-th term in polynomial expansion of the
49-
expression ``(1 + x) ** n``.
48+
to the coefficient of k-th term in polynomial expansion of
49+
``(1 + x)``.
5050

5151
Raises :exc:`TypeError` if either of the arguments are not integers.
5252
Raises :exc:`ValueError` if either of the arguments are negative.

Doc/library/random.rst

+4-4
Original file line numberDiff line numberDiff line change
@@ -130,9 +130,9 @@ Functions for integers
130130

131131
The positional argument pattern matches the :func:`range` function.
132132

133-
Keyword arguments should not be used because they can interpreted
134-
in unexpected ways. For example ``range(start=100)`` is interpreted
135-
as ``range(0, 100, 1)``.
133+
Keyword arguments should not be used because they can be interpreted
134+
in unexpected ways. For example ``randrange(start=100)`` is interpreted
135+
as ``randrange(0, 100, 1)``.
136136

137137
.. versionchanged:: 3.2
138138
:meth:`randrange` is more sophisticated about producing equally distributed
@@ -152,7 +152,7 @@ Functions for integers
152152
.. function:: getrandbits(k)
153153

154154
Returns a non-negative Python integer with *k* random bits. This method
155-
is supplied with the MersenneTwister generator and some other generators
155+
is supplied with the Mersenne Twister generator and some other generators
156156
may also provide it as an optional part of the API. When available,
157157
:meth:`getrandbits` enables :meth:`randrange` to handle arbitrarily large
158158
ranges.

Doc/library/sqlite3.rst

+2-1
Original file line numberDiff line numberDiff line change
@@ -2274,7 +2274,8 @@ If the connection attribute :attr:`~Connection.isolation_level`
22742274
is not ``None``,
22752275
new transactions are implicitly opened before
22762276
:meth:`~Cursor.execute` and :meth:`~Cursor.executemany` executes
2277-
``INSERT``, ``UPDATE``, ``DELETE``, or ``REPLACE`` statements.
2277+
``INSERT``, ``UPDATE``, ``DELETE``, or ``REPLACE`` statements;
2278+
for other statements, no implicit transaction handling is performed.
22782279
Use the :meth:`~Connection.commit` and :meth:`~Connection.rollback` methods
22792280
to respectively commit and roll back pending transactions.
22802281
You can choose the underlying `SQLite transaction behaviour`_ —

Doc/library/stdtypes.rst

+3-3
Original file line numberDiff line numberDiff line change
@@ -353,7 +353,7 @@ Notes:
353353
The numeric literals accepted include the digits ``0`` to ``9`` or any
354354
Unicode equivalent (code points with the ``Nd`` property).
355355

356-
See https://www.unicode.org/Public/14.0.0/ucd/extracted/DerivedNumericType.txt
356+
See https://www.unicode.org/Public/15.0.0/ucd/extracted/DerivedNumericType.txt
357357
for a complete list of code points with the ``Nd`` property.
358358

359359

@@ -5493,15 +5493,15 @@ When an operation would exceed the limit, a :exc:`ValueError` is raised:
54935493
>>> _ = int('2' * 5432)
54945494
Traceback (most recent call last):
54955495
...
5496-
ValueError: Exceeds the limit (4300) for integer string conversion: value has 5432 digits.
5496+
ValueError: Exceeds the limit (4300) for integer string conversion: value has 5432 digits; use sys.set_int_max_str_digits() to increase the limit.
54975497
>>> i = int('2' * 4300)
54985498
>>> len(str(i))
54995499
4300
55005500
>>> i_squared = i*i
55015501
>>> len(str(i_squared))
55025502
Traceback (most recent call last):
55035503
...
5504-
ValueError: Exceeds the limit (4300) for integer string conversion: value has 8599 digits.
5504+
ValueError: Exceeds the limit (4300) for integer string conversion: value has 8599 digits; use sys.set_int_max_str_digits() to increase the limit.
55055505
>>> len(hex(i_squared))
55065506
7144
55075507
>>> assert int(hex(i_squared), base=16) == i*i # Hexadecimal is unlimited.

Doc/library/unicodedata.rst

+4-4
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,8 @@
1717

1818
This module provides access to the Unicode Character Database (UCD) which
1919
defines character properties for all Unicode characters. The data contained in
20-
this database is compiled from the `UCD version 14.0.0
21-
<https://www.unicode.org/Public/14.0.0/ucd>`_.
20+
this database is compiled from the `UCD version 15.0.0
21+
<https://www.unicode.org/Public/15.0.0/ucd>`_.
2222

2323
The module uses the same names and symbols as defined by Unicode
2424
Standard Annex #44, `"Unicode Character Database"
@@ -175,6 +175,6 @@ Examples:
175175

176176
.. rubric:: Footnotes
177177

178-
.. [#] https://www.unicode.org/Public/14.0.0/ucd/NameAliases.txt
178+
.. [#] https://www.unicode.org/Public/15.0.0/ucd/NameAliases.txt
179179
180-
.. [#] https://www.unicode.org/Public/14.0.0/ucd/NamedSequences.txt
180+
.. [#] https://www.unicode.org/Public/15.0.0/ucd/NamedSequences.txt

Doc/reference/lexical_analysis.rst

+4-4
Original file line numberDiff line numberDiff line change
@@ -315,16 +315,16 @@ The Unicode category codes mentioned above stand for:
315315
* *Nd* - decimal numbers
316316
* *Pc* - connector punctuations
317317
* *Other_ID_Start* - explicit list of characters in `PropList.txt
318-
<https://www.unicode.org/Public/14.0.0/ucd/PropList.txt>`_ to support backwards
318+
<https://www.unicode.org/Public/15.0.0/ucd/PropList.txt>`_ to support backwards
319319
compatibility
320320
* *Other_ID_Continue* - likewise
321321

322322
All identifiers are converted into the normal form NFKC while parsing; comparison
323323
of identifiers is based on NFKC.
324324

325325
A non-normative HTML file listing all valid identifier characters for Unicode
326-
14.0.0 can be found at
327-
https://www.unicode.org/Public/14.0.0/ucd/DerivedCoreProperties.txt
326+
15.0.0 can be found at
327+
https://www.unicode.org/Public/15.0.0/ucd/DerivedCoreProperties.txt
328328

329329

330330
.. _keywords:
@@ -1013,4 +1013,4 @@ occurrence outside string literals and comments is an unconditional error:
10131013
10141014
.. rubric:: Footnotes
10151015

1016-
.. [#] https://www.unicode.org/Public/11.0.0/ucd/NameAliases.txt
1016+
.. [#] https://www.unicode.org/Public/15.0.0/ucd/NameAliases.txt

Doc/using/configure.rst

+3
Original file line numberDiff line numberDiff line change
@@ -232,6 +232,9 @@ also be used to improve performance.
232232
.. versionadded:: 3.11
233233
To use ThinLTO feature, use ``--with-lto=thin`` on Clang.
234234

235+
.. versionchanged:: 3.12
236+
Use ThinLTO as the default optimization policy on Clang if the compiler accepts the flag.
237+
235238
.. cmdoption:: --enable-bolt
236239

237240
Enable usage of the `BOLT post-link binary optimizer

0 commit comments

Comments
 (0)