Skip to content

Commit b52f8bd

Browse files
committed
Merge remote-tracking branch 'upstream/main' into decimal/contextvar
2 parents 4e98c02 + 3406f8c commit b52f8bd

Some content is hidden

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

73 files changed

+2152
-1319
lines changed

Doc/library/itertools.rst

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1085,8 +1085,8 @@ The following recipes have a more mathematical flavor:
10851085
kernel = tuple(kernel)[::-1]
10861086
n = len(kernel)
10871087
padded_signal = chain(repeat(0, n-1), signal, repeat(0, n-1))
1088-
for window in sliding_window(padded_signal, n):
1089-
yield math.sumprod(kernel, window)
1088+
windowed_signal = sliding_window(padded_signal, n)
1089+
return map(math.sumprod, repeat(kernel), windowed_signal)
10901090

10911091
def polynomial_from_roots(roots):
10921092
"""Compute a polynomial's coefficients from its roots.

Doc/library/unittest.mock.rst

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -205,8 +205,10 @@ The Mock Class
205205
import asyncio
206206
import inspect
207207
import unittest
208+
import threading
208209
from unittest.mock import sentinel, DEFAULT, ANY
209210
from unittest.mock import patch, call, Mock, MagicMock, PropertyMock, AsyncMock
211+
from unittest.mock import ThreadingMock
210212
from unittest.mock import mock_open
211213

212214
:class:`Mock` is a flexible mock object intended to replace the use of stubs and
@@ -1099,6 +1101,51 @@ object::
10991101
[call('foo'), call('bar')]
11001102

11011103

1104+
.. class:: ThreadingMock(spec=None, side_effect=None, return_value=DEFAULT, wraps=None, name=None, spec_set=None, unsafe=False, *, timeout=UNSET, **kwargs)
1105+
1106+
A version of :class:`MagicMock` for multithreading tests. The
1107+
:class:`ThreadingMock` object provides extra methods to wait for a call to
1108+
be invoked, rather than assert on it immediately.
1109+
1110+
The default timeout is specified by the ``timeout`` argument, or if unset by the
1111+
:attr:`ThreadingMock.DEFAULT_TIMEOUT` attribute, which defaults to blocking (``None``).
1112+
1113+
You can configure the global default timeout by setting :attr:`ThreadingMock.DEFAULT_TIMEOUT`.
1114+
1115+
.. method:: wait_until_called(*, timeout=UNSET)
1116+
1117+
Waits until the mock is called.
1118+
1119+
If a timeout was passed at the creation of the mock or if a timeout
1120+
argument is passed to this function, the function raises an
1121+
:exc:`AssertionError` if the call is not performed in time.
1122+
1123+
>>> mock = ThreadingMock()
1124+
>>> thread = threading.Thread(target=mock)
1125+
>>> thread.start()
1126+
>>> mock.wait_until_called(timeout=1)
1127+
>>> thread.join()
1128+
1129+
.. method:: wait_until_any_call(*args, **kwargs)
1130+
1131+
Waits until the the mock is called with the specified arguments.
1132+
1133+
If a timeout was passed at the creation of the mock
1134+
the function raises an :exc:`AssertionError` if the call is not performed in time.
1135+
1136+
>>> mock = ThreadingMock()
1137+
>>> thread = threading.Thread(target=mock, args=("arg1", "arg2",), kwargs={"arg": "thing"})
1138+
>>> thread.start()
1139+
>>> mock.wait_until_any_call("arg1", "arg2", arg="thing")
1140+
>>> thread.join()
1141+
1142+
.. attribute:: DEFAULT_TIMEOUT
1143+
1144+
Global default timeout in seconds to create instances of :class:`ThreadingMock`.
1145+
1146+
.. versionadded:: 3.13
1147+
1148+
11021149
Calling
11031150
~~~~~~~
11041151

Doc/reference/expressions.rst

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -298,27 +298,27 @@ Dictionary displays
298298
.. index::
299299
pair: dictionary; display
300300
pair: dictionary; comprehensions
301-
key, datum, key/datum pair
301+
key, value, key/value pair
302302
pair: object; dictionary
303303
single: {} (curly brackets); dictionary expression
304304
single: : (colon); in dictionary expressions
305305
single: , (comma); in dictionary displays
306306

307-
A dictionary display is a possibly empty series of key/datum pairs enclosed in
308-
curly braces:
307+
A dictionary display is a possibly empty series of dict items (key/value pairs)
308+
enclosed in curly braces:
309309

310310
.. productionlist:: python-grammar
311-
dict_display: "{" [`key_datum_list` | `dict_comprehension`] "}"
312-
key_datum_list: `key_datum` ("," `key_datum`)* [","]
313-
key_datum: `expression` ":" `expression` | "**" `or_expr`
311+
dict_display: "{" [`dict_item_list` | `dict_comprehension`] "}"
312+
dict_item_list: `dict_item` ("," `dict_item`)* [","]
313+
dict_item: `expression` ":" `expression` | "**" `or_expr`
314314
dict_comprehension: `expression` ":" `expression` `comp_for`
315315

316316
A dictionary display yields a new dictionary object.
317317

318-
If a comma-separated sequence of key/datum pairs is given, they are evaluated
318+
If a comma-separated sequence of dict items is given, they are evaluated
319319
from left to right to define the entries of the dictionary: each key object is
320-
used as a key into the dictionary to store the corresponding datum. This means
321-
that you can specify the same key multiple times in the key/datum list, and the
320+
used as a key into the dictionary to store the corresponding value. This means
321+
that you can specify the same key multiple times in the dict item list, and the
322322
final dictionary's value for that key will be the last one given.
323323

324324
.. index::
@@ -328,7 +328,7 @@ final dictionary's value for that key will be the last one given.
328328
A double asterisk ``**`` denotes :dfn:`dictionary unpacking`.
329329
Its operand must be a :term:`mapping`. Each mapping item is added
330330
to the new dictionary. Later values replace values already set by
331-
earlier key/datum pairs and earlier dictionary unpackings.
331+
earlier dict items and earlier dictionary unpackings.
332332

333333
.. versionadded:: 3.5
334334
Unpacking into dictionary displays, originally proposed by :pep:`448`.
@@ -344,7 +344,7 @@ in the new dictionary in the order they are produced.
344344
Restrictions on the types of the key values are listed earlier in section
345345
:ref:`types`. (To summarize, the key type should be :term:`hashable`, which excludes
346346
all mutable objects.) Clashes between duplicate keys are not detected; the last
347-
datum (textually rightmost in the display) stored for a given key value
347+
value (textually rightmost in the display) stored for a given key value
348348
prevails.
349349

350350
.. versionchanged:: 3.8

Doc/reference/simple_stmts.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -210,7 +210,7 @@ Assignment of an object to a single target is recursively defined as follows.
210210

211211
If the primary is a mapping object (such as a dictionary), the subscript must
212212
have a type compatible with the mapping's key type, and the mapping is then
213-
asked to create a key/datum pair which maps the subscript to the assigned
213+
asked to create a key/value pair which maps the subscript to the assigned
214214
object. This can either replace an existing key/value pair with the same key
215215
value, or insert a new key/value pair (if no key with the same value existed).
216216

Include/cpython/import.h

Lines changed: 0 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -4,23 +4,6 @@
44

55
PyMODINIT_FUNC PyInit__imp(void);
66

7-
PyAPI_FUNC(int) _PyImport_IsInitialized(PyInterpreterState *);
8-
9-
PyAPI_FUNC(PyObject *) _PyImport_GetModuleId(_Py_Identifier *name);
10-
PyAPI_FUNC(int) _PyImport_SetModule(PyObject *name, PyObject *module);
11-
PyAPI_FUNC(int) _PyImport_SetModuleString(const char *name, PyObject* module);
12-
13-
PyAPI_FUNC(void) _PyImport_AcquireLock(PyInterpreterState *interp);
14-
PyAPI_FUNC(int) _PyImport_ReleaseLock(PyInterpreterState *interp);
15-
16-
PyAPI_FUNC(int) _PyImport_FixupBuiltin(
17-
PyObject *mod,
18-
const char *name, /* UTF-8 encoded string */
19-
PyObject *modules
20-
);
21-
PyAPI_FUNC(int) _PyImport_FixupExtensionObject(PyObject*, PyObject *,
22-
PyObject *, PyObject *);
23-
247
struct _inittab {
258
const char *name; /* ASCII encoded string */
269
PyObject* (*initfunc)(void);
@@ -41,6 +24,3 @@ struct _frozen {
4124
collection of frozen modules: */
4225

4326
PyAPI_DATA(const struct _frozen *) PyImport_FrozenModules;
44-
45-
PyAPI_DATA(PyObject *) _PyImport_GetModuleAttr(PyObject *, PyObject *);
46-
PyAPI_DATA(PyObject *) _PyImport_GetModuleAttrString(const char *, const char *);

Include/cpython/modsupport.h

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -11,12 +11,9 @@ PyAPI_FUNC(int) _PyArg_UnpackStack(
1111
...);
1212

1313
PyAPI_FUNC(int) _PyArg_NoKeywords(const char *funcname, PyObject *kwargs);
14-
PyAPI_FUNC(int) _PyArg_NoKwnames(const char *funcname, PyObject *kwnames);
1514
PyAPI_FUNC(int) _PyArg_NoPositional(const char *funcname, PyObject *args);
1615
#define _PyArg_NoKeywords(funcname, kwargs) \
1716
((kwargs) == NULL || _PyArg_NoKeywords((funcname), (kwargs)))
18-
#define _PyArg_NoKwnames(funcname, kwnames) \
19-
((kwnames) == NULL || _PyArg_NoKwnames((funcname), (kwnames)))
2017
#define _PyArg_NoPositional(funcname, args) \
2118
((args) == NULL || _PyArg_NoPositional((funcname), (args)))
2219

@@ -29,13 +26,6 @@ PyAPI_FUNC(int) _PyArg_CheckPositional(const char *, Py_ssize_t,
2926
((!_Py_ANY_VARARGS(max) && (min) <= (nargs) && (nargs) <= (max)) \
3027
|| _PyArg_CheckPositional((funcname), (nargs), (min), (max)))
3128

32-
PyAPI_FUNC(PyObject **) _Py_VaBuildStack(
33-
PyObject **small_stack,
34-
Py_ssize_t small_stack_len,
35-
const char *format,
36-
va_list va,
37-
Py_ssize_t *p_nargs);
38-
3929
typedef struct _PyArg_Parser {
4030
int initialized;
4131
const char *format;
@@ -83,5 +73,3 @@ PyAPI_FUNC(PyObject * const *) _PyArg_UnpackKeywordsWithVararg(
8373
(minpos) <= (nargs) && (nargs) <= (maxpos) && (args) != NULL) ? (args) : \
8474
_PyArg_UnpackKeywords((args), (nargs), (kwargs), (kwnames), (parser), \
8575
(minpos), (maxpos), (minkw), (buf)))
86-
87-
PyAPI_FUNC(PyObject *) _PyModule_CreateInitialized(PyModuleDef*, int apiver);

Include/cpython/pyerrors.h

Lines changed: 0 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -91,39 +91,21 @@ typedef PyOSErrorObject PyWindowsErrorObject;
9191
/* Error handling definitions */
9292

9393
PyAPI_FUNC(void) _PyErr_SetKeyError(PyObject *);
94-
PyAPI_FUNC(_PyErr_StackItem*) _PyErr_GetTopmostException(PyThreadState *tstate);
95-
PyAPI_FUNC(PyObject*) _PyErr_GetHandledException(PyThreadState *);
96-
PyAPI_FUNC(void) _PyErr_SetHandledException(PyThreadState *, PyObject *);
97-
PyAPI_FUNC(void) _PyErr_GetExcInfo(PyThreadState *, PyObject **, PyObject **, PyObject **);
9894

9995
/* Context manipulation (PEP 3134) */
10096

10197
Py_DEPRECATED(3.12) PyAPI_FUNC(void) _PyErr_ChainExceptions(PyObject *, PyObject *, PyObject *);
10298
PyAPI_FUNC(void) _PyErr_ChainExceptions1(PyObject *);
10399

104-
/* Like PyErr_Format(), but saves current exception as __context__ and
105-
__cause__.
106-
*/
107-
PyAPI_FUNC(PyObject *) _PyErr_FormatFromCause(
108-
PyObject *exception,
109-
const char *format, /* ASCII-encoded string */
110-
...
111-
);
112-
113100
/* In exceptions.c */
114101

115-
PyAPI_FUNC(int) _PyException_AddNote(
116-
PyObject *exc,
117-
PyObject *note);
118-
119102
PyAPI_FUNC(PyObject*) PyUnstable_Exc_PrepReraiseStar(
120103
PyObject *orig,
121104
PyObject *excs);
122105

123106
/* In signalmodule.c */
124107

125108
int PySignal_SetWakeupFd(int fd);
126-
PyAPI_FUNC(int) _PyErr_CheckSignals(void);
127109

128110
/* Support for adding program text to SyntaxErrors */
129111

@@ -143,18 +125,6 @@ PyAPI_FUNC(PyObject *) PyErr_ProgramTextObject(
143125
PyObject *filename,
144126
int lineno);
145127

146-
PyAPI_FUNC(PyObject *) _PyErr_ProgramDecodedTextObject(
147-
PyObject *filename,
148-
int lineno,
149-
const char* encoding);
150-
151-
PyAPI_FUNC(PyObject *) _PyUnicodeTranslateError_Create(
152-
PyObject *object,
153-
Py_ssize_t start,
154-
Py_ssize_t end,
155-
const char *reason /* UTF-8 encoded string */
156-
);
157-
158128
PyAPI_FUNC(void) _PyErr_WriteUnraisableMsg(
159129
const char *err_msg,
160130
PyObject *obj);
@@ -163,16 +133,4 @@ PyAPI_FUNC(void) _Py_NO_RETURN _Py_FatalErrorFunc(
163133
const char *func,
164134
const char *message);
165135

166-
PyAPI_FUNC(void) _Py_NO_RETURN _Py_FatalErrorFormat(
167-
const char *func,
168-
const char *format,
169-
...);
170-
171-
extern PyObject *_PyErr_SetImportErrorWithNameFrom(
172-
PyObject *,
173-
PyObject *,
174-
PyObject *,
175-
PyObject *);
176-
177-
178136
#define Py_FatalError(message) _Py_FatalErrorFunc(__func__, (message))

0 commit comments

Comments
 (0)