Skip to content

Commit bd65c8b

Browse files
committed
Merge branch 'main' into eager-tasks-factory
2 parents 4228c69 + 1ca3155 commit bd65c8b

File tree

99 files changed

+1641
-1915
lines changed

Some content is hidden

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

99 files changed

+1641
-1915
lines changed

Doc/c-api/object.rst

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -179,6 +179,15 @@ Object Protocol
179179
If *o1* and *o2* are the same object, :c:func:`PyObject_RichCompareBool`
180180
will always return ``1`` for :const:`Py_EQ` and ``0`` for :const:`Py_NE`.
181181
182+
.. c:function:: PyObject* PyObject_Format(PyObject *obj, PyObject *format_spec)
183+
184+
Format *obj* using *format_spec*. This is equivalent to the Python
185+
expression ``format(obj, format_spec)``.
186+
187+
*format_spec* may be ``NULL``. In this case the call is equivalent
188+
to ``format(obj)``.
189+
Returns the formatted string on success, ``NULL`` on failure.
190+
182191
.. c:function:: PyObject* PyObject_Repr(PyObject *o)
183192
184193
.. index:: builtin: repr

Doc/library/itertools.rst

Lines changed: 18 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -195,7 +195,7 @@ loops that truncate the stream.
195195
if n < 1:
196196
raise ValueError('n must be at least one')
197197
it = iter(iterable)
198-
while (batch := tuple(islice(it, n))):
198+
while batch := tuple(islice(it, n)):
199199
yield batch
200200

201201
.. versionadded:: 3.12
@@ -866,26 +866,29 @@ which incur interpreter overhead.
866866
window.append(x)
867867
yield math.sumprod(kernel, window)
868868

869-
def polynomial_eval(coefficients, x):
870-
"Evaluate a polynomial at a specific value."
871-
# polynomial_eval([1, -4, -17, 60], x=2.5) --> 8.125 x³ -4x² -17x + 60
872-
n = len(coefficients)
873-
if n == 0:
874-
return x * 0 # coerce zero to the type of x
875-
powers = list(accumulate(repeat(x, n - 1), operator.mul, initial=1))
876-
return math.sumprod(coefficients, reversed(powers))
877-
878869
def polynomial_from_roots(roots):
879870
"""Compute a polynomial's coefficients from its roots.
880871

881872
(x - 5) (x + 4) (x - 3) expands to: x³ -4x² -17x + 60
882873
"""
883874
# polynomial_from_roots([5, -4, 3]) --> [1, -4, -17, 60]
884-
roots = list(map(operator.neg, roots))
885-
return [
886-
sum(map(math.prod, combinations(roots, k)))
887-
for k in range(len(roots) + 1)
888-
]
875+
expansion = [1]
876+
for r in roots:
877+
expansion = convolve(expansion, (1, -r))
878+
return list(expansion)
879+
880+
def polynomial_eval(coefficients, x):
881+
"""Evaluate a polynomial at a specific value.
882+
883+
Computes with better numeric stability than Horner's method.
884+
"""
885+
# Evaluate x³ -4x² -17x + 60 at x = 2.5
886+
# polynomial_eval([1, -4, -17, 60], x=2.5) --> 8.125
887+
n = len(coefficients)
888+
if n == 0:
889+
return x * 0 # coerce zero to the type of x
890+
powers = map(pow, repeat(x), reversed(range(n)))
891+
return math.sumprod(coefficients, powers)
889892

890893
def iter_index(iterable, value, start=0):
891894
"Return indices where a value occurs in a sequence or iterable."

Doc/library/os.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3951,7 +3951,7 @@ to be ignored.
39513951

39523952
.. note::
39533953

3954-
The standard way to exit is ``sys.exit(n)``. :func:`_exit` should
3954+
The standard way to exit is :func:`sys.exit(n) <sys.exit>`. :func:`!_exit` should
39553955
normally only be used in the child process after a :func:`fork`.
39563956

39573957
The following exit codes are defined and can be used with :func:`_exit`,

Doc/library/pdb.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -513,7 +513,7 @@ can be overridden by the local file.
513513
:file:`.pdbrc` file)::
514514

515515
# Print instance variables (usage "pi classInst")
516-
alias pi for k in %1.__dict__.keys(): print("%1.",k,"=",%1.__dict__[k])
516+
alias pi for k in %1.__dict__.keys(): print(f"%1.{k} = {%1.__dict__[k]}")
517517
# Print instance variables in self
518518
alias ps pi self
519519

Doc/library/sqlite3.rst

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -272,9 +272,9 @@ Module functions
272272

273273
:param float timeout:
274274
How many seconds the connection should wait before raising
275-
an exception, if the database is locked by another connection.
276-
If another connection opens a transaction to modify the database,
277-
it will be locked until that transaction is committed.
275+
an :exc:`OperationalError` when a table is locked.
276+
If another connection opens a transaction to modify a table,
277+
that table will be locked until the transaction is committed.
278278
Default five seconds.
279279

280280
:param int detect_types:
@@ -911,7 +911,7 @@ Connection objects
911911

912912
Call this method from a different thread to abort any queries that might
913913
be executing on the connection.
914-
Aborted queries will raise an exception.
914+
Aborted queries will raise an :exc:`OperationalError`.
915915

916916

917917
.. method:: set_authorizer(authorizer_callback)

Doc/library/ssl.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1218,7 +1218,7 @@ SSL sockets also have the following additional methods and attributes:
12181218

12191219
.. method:: SSLSocket.shared_ciphers()
12201220

1221-
Return the list of ciphers shared by the client during the handshake. Each
1221+
Return the list of ciphers available in both the client and server. Each
12221222
entry of the returned list is a three-value tuple containing the name of the
12231223
cipher, the version of the SSL protocol that defines its use, and the number
12241224
of secret bits the cipher uses. :meth:`~SSLSocket.shared_ciphers` returns

Doc/whatsnew/3.12.rst

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -339,7 +339,8 @@ shutil
339339

340340
* :func:`shutil.rmtree` now accepts a new argument *onexc* which is an
341341
error handler like *onerror* but which expects an exception instance
342-
rather than a *(typ, val, tb)* triplet. *onerror* is deprecated.
342+
rather than a *(typ, val, tb)* triplet. *onerror* is deprecated and
343+
will be removed in Python 3.14.
343344
(Contributed by Irit Katriel in :gh:`102828`.)
344345

345346

@@ -508,8 +509,8 @@ Deprecated
508509
fields are deprecated. Use :data:`sys.last_exc` instead.
509510
(Contributed by Irit Katriel in :gh:`102778`.)
510511

511-
* The *onerror* argument of :func:`shutil.rmtree` is deprecated. Use *onexc*
512-
instead. (Contributed by Irit Katriel in :gh:`102828`.)
512+
* The *onerror* argument of :func:`shutil.rmtree` is deprecated as will be removed
513+
in Python 3.14. Use *onexc* instead. (Contributed by Irit Katriel in :gh:`102828`.)
513514

514515

515516
Pending Removal in Python 3.13
@@ -591,6 +592,9 @@ Pending Removal in Python 3.14
591592
functions that have been deprecated since Python 2 but only gained a
592593
proper :exc:`DeprecationWarning` in 3.12. Remove them in 3.14.
593594

595+
* The *onerror* argument of :func:`shutil.rmtree` is deprecated in 3.12,
596+
and will be removed in 3.14.
597+
594598
Pending Removal in Future Versions
595599
----------------------------------
596600

Include/cpython/initconfig.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ PyAPI_FUNC(PyStatus) PyStatus_Exit(int exitcode);
2525
PyAPI_FUNC(int) PyStatus_IsError(PyStatus err);
2626
PyAPI_FUNC(int) PyStatus_IsExit(PyStatus err);
2727
PyAPI_FUNC(int) PyStatus_Exception(PyStatus err);
28+
PyAPI_FUNC(PyObject *) _PyErr_SetFromPyStatus(PyStatus status);
2829

2930
/* --- PyWideStringList ------------------------------------------------ */
3031

Include/cpython/longintrepr.h

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ typedef long stwodigits; /* signed variant of twodigits */
8080
*/
8181

8282
typedef struct _PyLongValue {
83-
Py_ssize_t ob_size; /* Number of items in variable part */
83+
uintptr_t lv_tag; /* Number of digits, sign and flags */
8484
digit ob_digit[1];
8585
} _PyLongValue;
8686

@@ -94,6 +94,10 @@ PyAPI_FUNC(PyLongObject *) _PyLong_New(Py_ssize_t);
9494
/* Return a copy of src. */
9595
PyAPI_FUNC(PyObject *) _PyLong_Copy(PyLongObject *src);
9696

97+
PyAPI_FUNC(PyLongObject *)
98+
_PyLong_FromDigits(int negative, Py_ssize_t digit_count, digit *digits);
99+
100+
97101
#ifdef __cplusplus
98102
}
99103
#endif

Include/cpython/object.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ PyAPI_FUNC(void) _Py_ForgetReference(PyObject *);
1515
PyAPI_FUNC(Py_ssize_t) _Py_GetGlobalRefTotal(void);
1616
# define _Py_GetRefTotal() _Py_GetGlobalRefTotal()
1717
PyAPI_FUNC(Py_ssize_t) _Py_GetLegacyRefTotal(void);
18+
PyAPI_FUNC(Py_ssize_t) _PyInterpreterState_GetRefTotal(PyInterpreterState *);
1819
#endif
1920

2021

Include/cpython/pyerrors.h

Lines changed: 0 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -116,24 +116,6 @@ PyAPI_FUNC(int) _PyException_AddNote(
116116
PyObject *exc,
117117
PyObject *note);
118118

119-
/* Helper that attempts to replace the current exception with one of the
120-
* same type but with a prefix added to the exception text. The resulting
121-
* exception description looks like:
122-
*
123-
* prefix (exc_type: original_exc_str)
124-
*
125-
* Only some exceptions can be safely replaced. If the function determines
126-
* it isn't safe to perform the replacement, it will leave the original
127-
* unmodified exception in place.
128-
*
129-
* Returns a borrowed reference to the new exception (if any), NULL if the
130-
* existing exception was left in place.
131-
*/
132-
PyAPI_FUNC(PyObject *) _PyErr_TrySetFromCause(
133-
const char *prefix_format, /* ASCII-encoded string */
134-
...
135-
);
136-
137119
/* In signalmodule.c */
138120

139121
int PySignal_SetWakeupFd(int fd);

Include/cpython/pylifecycle.h

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -62,5 +62,6 @@ PyAPI_FUNC(int) _Py_CoerceLegacyLocale(int warn);
6262
PyAPI_FUNC(int) _Py_LegacyLocaleDetected(int warn);
6363
PyAPI_FUNC(char *) _Py_SetLocaleFromEnv(int category);
6464

65-
PyAPI_FUNC(PyThreadState *) _Py_NewInterpreterFromConfig(
66-
const _PyInterpreterConfig *);
65+
PyAPI_FUNC(PyStatus) _Py_NewInterpreterFromConfig(
66+
PyThreadState **tstate_p,
67+
const _PyInterpreterConfig *config);

Include/internal/pycore_initconfig.h

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,8 +44,6 @@ struct pyruntimestate;
4444
#define _PyStatus_UPDATE_FUNC(err) \
4545
do { (err).func = _PyStatus_GET_FUNC(); } while (0)
4646

47-
PyObject* _PyErr_SetFromPyStatus(PyStatus status);
48-
4947
/* --- PyWideStringList ------------------------------------------------ */
5048

5149
#define _PyWideStringList_INIT (PyWideStringList){.length = 0, .items = NULL}

Include/internal/pycore_interp.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ extern "C" {
2525
#include "pycore_import.h" // struct _import_state
2626
#include "pycore_list.h" // struct _Py_list_state
2727
#include "pycore_global_objects.h" // struct _Py_interp_static_objects
28+
#include "pycore_object_state.h" // struct _py_object_state
2829
#include "pycore_tuple.h" // struct _Py_tuple_state
2930
#include "pycore_typeobject.h" // struct type_cache
3031
#include "pycore_unicodeobject.h" // struct _Py_unicode_state
@@ -138,6 +139,7 @@ struct _is {
138139
// One bit is set for each non-NULL entry in code_watchers
139140
uint8_t active_code_watchers;
140141

142+
struct _py_object_state object_state;
141143
struct _Py_unicode_state unicode;
142144
struct _Py_float_state float_state;
143145
struct _Py_long_state long_state;

0 commit comments

Comments
 (0)