summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorErlend E. Aasland <erlend@python.org>2024-05-27 22:02:46 (GMT)
committerGitHub <noreply@github.com>2024-05-27 22:02:46 (GMT)
commit3e8b60905e97a4fe89bb24180063732214368938 (patch)
tree39f3869631ffe1932632db259cfa69a9f114118f
parentae7b17673f29efe17b416cbcfbf43b5b3ff5977c (diff)
downloadcpython-3e8b60905e97a4fe89bb24180063732214368938.zip
cpython-3e8b60905e97a4fe89bb24180063732214368938.tar.gz
cpython-3e8b60905e97a4fe89bb24180063732214368938.tar.bz2
gh-117398: Add multiphase support to _datetime (gh-119373)
This is minimal support. Subinterpreters are not supported yet. That will be addressed in a later change. Co-authored-by: Eric Snow <ericsnowcurrently@gmail.com>
-rw-r--r--Lib/test/datetimetester.py21
-rw-r--r--Modules/_datetimemodule.c26
2 files changed, 32 insertions, 15 deletions
diff --git a/Lib/test/datetimetester.py b/Lib/test/datetimetester.py
index b3838d5..ba7f185 100644
--- a/Lib/test/datetimetester.py
+++ b/Lib/test/datetimetester.py
@@ -47,6 +47,26 @@ except ImportError:
pass
#
+# This is copied from test_import/__init__.py.
+# XXX Move it to support/__init__.py.
+def no_rerun(reason):
+ """Skip rerunning for a particular test.
+
+ WARNING: Use this decorator with care; skipping rerunning makes it
+ impossible to find reference leaks. Provide a clear reason for skipping the
+ test using the 'reason' parameter.
+ """
+ def deco(func):
+ _has_run = False
+ def wrapper(self):
+ nonlocal _has_run
+ if _has_run:
+ self.skipTest(reason)
+ func(self)
+ _has_run = True
+ return wrapper
+ return deco
+
pickle_loads = {pickle.loads, pickle._loads}
pickle_choices = [(pickle, pickle, proto)
@@ -6383,6 +6403,7 @@ class IranTest(ZoneInfoTest):
@unittest.skipIf(_testcapi is None, 'need _testcapi module')
+@no_rerun("the encapsulated datetime C API does not support reloading")
class CapiTest(unittest.TestCase):
def setUp(self):
# Since the C API is not present in the _Pure tests, skip all tests
diff --git a/Modules/_datetimemodule.c b/Modules/_datetimemodule.c
index 3c6d270..271b37d 100644
--- a/Modules/_datetimemodule.c
+++ b/Modules/_datetimemodule.c
@@ -7040,30 +7040,26 @@ error:
}
#undef DATETIME_ADD_MACRO
-static struct PyModuleDef datetimemodule = {
+static PyModuleDef_Slot module_slots[] = {
+ {Py_mod_exec, _datetime_exec},
+ {Py_mod_multiple_interpreters, Py_MOD_MULTIPLE_INTERPRETERS_NOT_SUPPORTED},
+ {Py_mod_gil, Py_MOD_GIL_NOT_USED},
+ {0, NULL},
+};
+
+static PyModuleDef datetimemodule = {
.m_base = PyModuleDef_HEAD_INIT,
.m_name = "_datetime",
.m_doc = "Fast implementation of the datetime type.",
- .m_size = -1,
+ .m_size = 0,
.m_methods = module_methods,
+ .m_slots = module_slots,
};
PyMODINIT_FUNC
PyInit__datetime(void)
{
- PyObject *mod = PyModule_Create(&datetimemodule);
- if (mod == NULL)
- return NULL;
-#ifdef Py_GIL_DISABLED
- PyUnstable_Module_SetGIL(mod, Py_MOD_GIL_NOT_USED);
-#endif
-
- if (_datetime_exec(mod) < 0) {
- Py_DECREF(mod);
- return NULL;
- }
-
- return mod;
+ return PyModuleDef_Init(&datetimemodule);
}
/* ---------------------------------------------------------------------------