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; }