Skip to content

Commit b03c5db

Browse files
authored
Merge branch 'main' into fix-personalized-docs-heapq
2 parents 7a9906e + 3dadc22 commit b03c5db

16 files changed

Lines changed: 172 additions & 62 deletions

File tree

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/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: 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.
@@ -50,8 +51,21 @@ _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+
PyDateTime_IMPORT;
58+
if (PyErr_Occurred()) {
59+
return NULL;
60+
}
61+
62+
Py_RETURN_NONE;
63+
}
64+
65+
5366
static PyMethodDef _testcext_methods[] = {
5467
{"add", _testcext_add, METH_VARARGS, _testcext_add_doc},
68+
{"test_datetime", test_datetime, METH_NOARGS, NULL},
5569
{NULL, NULL, 0, NULL} // sentinel
5670
};
5771

@@ -65,12 +79,18 @@ _testcext_exec(
6579
#endif
6680
)
6781
{
82+
PyObject *result;
83+
6884
#ifdef __STDC_VERSION__
6985
if (PyModule_AddIntMacro(module, __STDC_VERSION__) < 0) {
7086
return -1;
7187
}
7288
#endif
7389

90+
result = PyObject_CallMethod(module, "test_datetime", "");
91+
if (!result) return -1;
92+
Py_DECREF(result);
93+
7494
// test Py_BUILD_ASSERT() and Py_BUILD_ASSERT_EXPR()
7595
Py_BUILD_ASSERT(sizeof(int) == sizeof(unsigned int));
7696
assert(Py_BUILD_ASSERT_EXPR(sizeof(int) == sizeof(unsigned int)) == 0);

Lib/test/test_cppext/extension.cpp

Lines changed: 17 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,23 @@ 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+
PyDateTime_IMPORT;
236+
if (PyErr_Occurred()) {
237+
return NULL;
238+
}
239+
240+
Py_RETURN_NONE;
241+
}
242+
231243
static PyMethodDef _testcppext_methods[] = {
232244
{"add", _testcppext_add, METH_VARARGS, _testcppext_add_doc},
233245
{"test_api_casts", test_api_casts, METH_NOARGS, _Py_NULL},
234246
{"test_unicode", test_unicode, METH_NOARGS, _Py_NULL},
235247
{"test_virtual_object", test_virtual_object, METH_NOARGS, _Py_NULL},
248+
{"test_datetime", test_datetime, METH_NOARGS, _Py_NULL},
236249
// Note: _testcppext_exec currently runs all test functions directly.
237250
// When adding a new one, add a call there.
238251

@@ -261,6 +274,10 @@ _testcppext_exec(PyObject *module)
261274
if (!result) return -1;
262275
Py_DECREF(result);
263276

277+
result = PyObject_CallMethod(module, "test_datetime", "");
278+
if (!result) return -1;
279+
Py_DECREF(result);
280+
264281
// test Py_BUILD_ASSERT() and Py_BUILD_ASSERT_EXPR()
265282
Py_BUILD_ASSERT(sizeof(int) == sizeof(unsigned int));
266283
assert(Py_BUILD_ASSERT_EXPR(sizeof(int) == sizeof(unsigned int)) == 0);
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Optimize and eliminate ref-counting in ``_BINARY_OP_SUBSCR_LIST_SLICE``

Modules/_testcapi/function.c

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,13 @@ function_set_closure(PyObject *self, PyObject *args)
123123
}
124124

125125

126+
static PyObject *
127+
function_get_annotations(PyObject *self, PyObject *func)
128+
{
129+
return Py_XNewRef(PyFunction_GetAnnotations(func));
130+
}
131+
132+
126133
static PyMethodDef test_methods[] = {
127134
{"function_get_code", function_get_code, METH_O, NULL},
128135
{"function_get_globals", function_get_globals, METH_O, NULL},
@@ -133,6 +140,7 @@ static PyMethodDef test_methods[] = {
133140
{"function_set_kw_defaults", function_set_kw_defaults, METH_VARARGS, NULL},
134141
{"function_get_closure", function_get_closure, METH_O, NULL},
135142
{"function_set_closure", function_set_closure, METH_VARARGS, NULL},
143+
{"function_get_annotations", function_get_annotations, METH_O, NULL},
136144
{NULL},
137145
};
138146

0 commit comments

Comments
 (0)