Skip to content

Commit 2a962b1

Browse files
committed
Merge branch 'main' into typeof
2 parents 0e3dda3 + 23d45f0 commit 2a962b1

File tree

21 files changed

+303
-70
lines changed

21 files changed

+303
-70
lines changed

Doc/library/asyncio-eventloop.rst

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -297,8 +297,9 @@ clocks to track time.
297297
are called is undefined.
298298

299299
The optional positional *args* will be passed to the callback when
300-
it is called. If you want the callback to be called with keyword
301-
arguments use :func:`functools.partial`.
300+
it is called. Use :func:`functools.partial`
301+
:ref:`to pass keyword arguments <asyncio-pass-keywords>` to
302+
*callback*.
302303

303304
An optional keyword-only *context* argument allows specifying a
304305
custom :class:`contextvars.Context` for the *callback* to run in.
@@ -1034,8 +1035,8 @@ Watching file descriptors
10341035
.. method:: loop.add_writer(fd, callback, *args)
10351036

10361037
Start monitoring the *fd* file descriptor for write availability and
1037-
invoke *callback* with the specified arguments once *fd* is available for
1038-
writing.
1038+
invoke *callback* with the specified arguments *args* once *fd* is
1039+
available for writing.
10391040

10401041
Any preexisting callback registered for *fd* is cancelled and replaced by
10411042
*callback*.
@@ -1308,7 +1309,8 @@ Unix signals
13081309

13091310
.. method:: loop.add_signal_handler(signum, callback, *args)
13101311

1311-
Set *callback* as the handler for the *signum* signal.
1312+
Set *callback* as the handler for the *signum* signal,
1313+
passing *args* as positional arguments.
13121314

13131315
The callback will be invoked by *loop*, along with other queued callbacks
13141316
and runnable coroutines of that event loop. Unlike signal handlers
@@ -1343,7 +1345,8 @@ Executing code in thread or process pools
13431345

13441346
.. awaitablemethod:: loop.run_in_executor(executor, func, *args)
13451347

1346-
Arrange for *func* to be called in the specified executor.
1348+
Arrange for *func* to be called in the specified executor
1349+
passing *args* as positional arguments.
13471350

13481351
The *executor* argument should be an :class:`concurrent.futures.Executor`
13491352
instance. The default executor is used if *executor* is ``None``.

Include/datetime.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -198,7 +198,7 @@ static PyDateTime_CAPI *PyDateTimeAPI = NULL;
198198

199199
static inline PyDateTime_CAPI *
200200
_PyDateTime_IMPORT(void) {
201-
PyDateTime_CAPI *val = _Py_atomic_load_ptr(&PyDateTimeAPI);
201+
PyDateTime_CAPI *val = (PyDateTime_CAPI *)_Py_atomic_load_ptr(&PyDateTimeAPI);
202202
if (val == NULL) {
203203
PyDateTime_CAPI *capi = (PyDateTime_CAPI *)PyCapsule_Import(
204204
PyDateTime_CAPSULE_NAME, 0);

Include/internal/pycore_opcode_metadata.h

Lines changed: 2 additions & 2 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: 1 addition & 1 deletion
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: 4 additions & 4 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Lib/importlib/_bootstrap.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1280,6 +1280,14 @@ def _find_and_load(name, import_):
12801280
# NOTE: because of this, initializing must be set *before*
12811281
# putting the new module in sys.modules.
12821282
_lock_unlock_module(name)
1283+
else:
1284+
# Verify the module is still in sys.modules. Another thread may have
1285+
# removed it (due to import failure) between our sys.modules.get()
1286+
# above and the _initializing check. If removed, we retry the import
1287+
# to preserve normal semantics: the caller gets the exception from
1288+
# the actual import failure rather than a synthetic error.
1289+
if sys.modules.get(name) is not module:
1290+
return _find_and_load(name, import_)
12831291

12841292
if module is None:
12851293
message = f'import of {name} halted; None in sys.modules'

Lib/test/test_capi/test_function.py

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -307,10 +307,27 @@ def function_without_closure(): ...
307307
_testcapi.function_get_closure(function_without_closure), (1, 2))
308308
self.assertEqual(function_without_closure.__closure__, (1, 2))
309309

310+
def test_function_get_annotations(self):
311+
# Test PyFunction_GetAnnotations()
312+
def normal():
313+
pass
314+
315+
def annofn(arg: int) -> str:
316+
return f'arg = {arg}'
317+
318+
annotations = _testcapi.function_get_annotations(normal)
319+
self.assertIsNone(annotations)
320+
321+
annotations = _testcapi.function_get_annotations(annofn)
322+
self.assertIsInstance(annotations, dict)
323+
self.assertEqual(annotations, annofn.__annotations__)
324+
325+
with self.assertRaises(SystemError):
326+
_testcapi.function_get_annotations(None)
327+
310328
# TODO: test PyFunction_New()
311329
# TODO: test PyFunction_NewWithQualName()
312330
# TODO: test PyFunction_SetVectorcall()
313-
# TODO: test PyFunction_GetAnnotations()
314331
# TODO: test PyFunction_SetAnnotations()
315332
# TODO: test PyClassMethod_New()
316333
# TODO: test PyStaticMethod_New()

Lib/test/test_capi/test_opt.py

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3660,6 +3660,23 @@ def testfunc(n):
36603660
self.assertLessEqual(count_ops(ex, "_POP_TOP_INT"), 1)
36613661
self.assertIn("_POP_TOP_NOP", uops)
36623662

3663+
def test_binary_subscr_list_slice(self):
3664+
def testfunc(n):
3665+
x = 0
3666+
for _ in range(n):
3667+
l = [1, 2, 3]
3668+
x += l[0:1][0]
3669+
return x
3670+
3671+
res, ex = self._run_with_optimizer(testfunc, TIER2_THRESHOLD)
3672+
self.assertEqual(res, TIER2_THRESHOLD)
3673+
uops = get_opnames(ex)
3674+
3675+
self.assertIn("_BINARY_OP_SUBSCR_LIST_SLICE", uops)
3676+
self.assertNotIn("_GUARD_TOS_LIST", uops)
3677+
self.assertEqual(count_ops(ex, "_POP_TOP"), 3)
3678+
self.assertEqual(count_ops(ex, "_POP_TOP_NOP"), 4)
3679+
36633680
def test_is_op(self):
36643681
def test_is_false(n):
36653682
a = object()

Lib/test/test_cext/extension.c

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
#endif
1212

1313
#include "Python.h"
14+
#include "datetime.h"
1415

1516
#ifdef TEST_INTERNAL_C_API
1617
// gh-135906: Check for compiler warnings in the internal C API.
@@ -50,8 +51,24 @@ _testcext_add(PyObject *Py_UNUSED(module), PyObject *args)
5051
}
5152

5253

54+
static PyObject *
55+
test_datetime(PyObject *Py_UNUSED(module), PyObject *Py_UNUSED(args))
56+
{
57+
// datetime.h is excluded from the limited C API
58+
#ifndef Py_LIMITED_API
59+
PyDateTime_IMPORT;
60+
if (PyErr_Occurred()) {
61+
return NULL;
62+
}
63+
#endif
64+
65+
Py_RETURN_NONE;
66+
}
67+
68+
5369
static PyMethodDef _testcext_methods[] = {
5470
{"add", _testcext_add, METH_VARARGS, _testcext_add_doc},
71+
{"test_datetime", test_datetime, METH_NOARGS, NULL},
5572
{NULL, NULL, 0, NULL} // sentinel
5673
};
5774

@@ -65,14 +82,18 @@ _testcext_exec(
6582
#endif
6683
)
6784
{
68-
PyObject *obj;
85+
PyObject *result, *obj;
6986

7087
#ifdef __STDC_VERSION__
7188
if (PyModule_AddIntMacro(module, __STDC_VERSION__) < 0) {
7289
return -1;
7390
}
7491
#endif
7592

93+
result = PyObject_CallMethod(module, "test_datetime", "");
94+
if (!result) return -1;
95+
Py_DECREF(result);
96+
7697
// test Py_BUILD_ASSERT() and Py_BUILD_ASSERT_EXPR()
7798
Py_BUILD_ASSERT(sizeof(int) == sizeof(unsigned int));
7899
assert(Py_BUILD_ASSERT_EXPR(sizeof(int) == sizeof(unsigned int)) == 0);

Lib/test/test_cppext/extension.cpp

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
#endif
1212

1313
#include "Python.h"
14+
#include "datetime.h"
1415

1516
#ifdef TEST_INTERNAL_C_API
1617
// gh-135906: Check for compiler warnings in the internal C API
@@ -228,11 +229,26 @@ test_virtual_object(PyObject *Py_UNUSED(module), PyObject *Py_UNUSED(args))
228229
Py_RETURN_NONE;
229230
}
230231

232+
static PyObject *
233+
test_datetime(PyObject *Py_UNUSED(module), PyObject *Py_UNUSED(args))
234+
{
235+
// datetime.h is excluded from the limited C API
236+
#ifndef Py_LIMITED_API
237+
PyDateTime_IMPORT;
238+
if (PyErr_Occurred()) {
239+
return NULL;
240+
}
241+
#endif
242+
243+
Py_RETURN_NONE;
244+
}
245+
231246
static PyMethodDef _testcppext_methods[] = {
232247
{"add", _testcppext_add, METH_VARARGS, _testcppext_add_doc},
233248
{"test_api_casts", test_api_casts, METH_NOARGS, _Py_NULL},
234249
{"test_unicode", test_unicode, METH_NOARGS, _Py_NULL},
235250
{"test_virtual_object", test_virtual_object, METH_NOARGS, _Py_NULL},
251+
{"test_datetime", test_datetime, METH_NOARGS, _Py_NULL},
236252
// Note: _testcppext_exec currently runs all test functions directly.
237253
// When adding a new one, add a call there.
238254

@@ -261,6 +277,10 @@ _testcppext_exec(PyObject *module)
261277
if (!result) return -1;
262278
Py_DECREF(result);
263279

280+
result = PyObject_CallMethod(module, "test_datetime", "");
281+
if (!result) return -1;
282+
Py_DECREF(result);
283+
264284
// test Py_BUILD_ASSERT() and Py_BUILD_ASSERT_EXPR()
265285
Py_BUILD_ASSERT(sizeof(int) == sizeof(unsigned int));
266286
assert(Py_BUILD_ASSERT_EXPR(sizeof(int) == sizeof(unsigned int)) == 0);

0 commit comments

Comments
 (0)