From 8a83739facc2223481910de25c9d3d1bff24ec6a Mon Sep 17 00:00:00 2001 From: Victor Stinner Date: Tue, 10 Feb 2026 16:13:40 +0100 Subject: [PATCH] gh-141563: Don't test datetime.h with the limited C API Fix test_cext and test_cppext. --- Lib/test/test_cext/extension.c | 3 +++ Lib/test/test_cppext/extension.cpp | 3 +++ 2 files changed, 6 insertions(+) diff --git a/Lib/test/test_cext/extension.c b/Lib/test/test_cext/extension.c index 20c2b6e89d8e17..28531b47383b85 100644 --- a/Lib/test/test_cext/extension.c +++ b/Lib/test/test_cext/extension.c @@ -54,10 +54,13 @@ _testcext_add(PyObject *Py_UNUSED(module), PyObject *args) static PyObject * test_datetime(PyObject *Py_UNUSED(module), PyObject *Py_UNUSED(args)) { + // datetime.h is excluded from the limited C API +#ifndef Py_LIMITED_API PyDateTime_IMPORT; if (PyErr_Occurred()) { return NULL; } +#endif Py_RETURN_NONE; } diff --git a/Lib/test/test_cppext/extension.cpp b/Lib/test/test_cppext/extension.cpp index 51271250366429..7d360f88fdd1f1 100644 --- a/Lib/test/test_cppext/extension.cpp +++ b/Lib/test/test_cppext/extension.cpp @@ -232,10 +232,13 @@ test_virtual_object(PyObject *Py_UNUSED(module), PyObject *Py_UNUSED(args)) static PyObject * test_datetime(PyObject *Py_UNUSED(module), PyObject *Py_UNUSED(args)) { + // datetime.h is excluded from the limited C API +#ifndef Py_LIMITED_API PyDateTime_IMPORT; if (PyErr_Occurred()) { return NULL; } +#endif Py_RETURN_NONE; }