Skip to content

Commit a678d8e

Browse files
authored
[3.12] gh-129405: Fix doc for Py_mod_multiple_interpreters default, and add test (GH-129406) (GH-130510)
1 parent e280c49 commit a678d8e

File tree

3 files changed

+48
-18
lines changed

3 files changed

+48
-18
lines changed

Doc/c-api/module.rst

+1-1
Original file line numberDiff line numberDiff line change
@@ -415,7 +415,7 @@ The available slot types are:
415415
in one module definition.
416416
417417
If ``Py_mod_multiple_interpreters`` is not specified, the import
418-
machinery defaults to ``Py_MOD_MULTIPLE_INTERPRETERS_NOT_SUPPORTED``.
418+
machinery defaults to ``Py_MOD_MULTIPLE_INTERPRETERS_SUPPORTED``.
419419
420420
.. versionadded:: 3.12
421421

Lib/test/test_import/__init__.py

+30-17
Original file line numberDiff line numberDiff line change
@@ -1900,6 +1900,7 @@ def test_single_init_extension_compat(self):
19001900

19011901
@unittest.skipIf(_testmultiphase is None, "test requires _testmultiphase module")
19021902
def test_multi_init_extension_compat(self):
1903+
# Module with Py_MOD_PER_INTERPRETER_GIL_SUPPORTED
19031904
module = '_testmultiphase'
19041905
require_extension(module)
19051906
with self.subTest(f'{module}: not strict'):
@@ -1911,6 +1912,8 @@ def test_multi_init_extension_compat(self):
19111912

19121913
@unittest.skipIf(_testmultiphase is None, "test requires _testmultiphase module")
19131914
def test_multi_init_extension_non_isolated_compat(self):
1915+
# Module with Py_MOD_MULTIPLE_INTERPRETERS_NOT_SUPPORTED
1916+
# and Py_MOD_GIL_NOT_USED
19141917
modname = '_test_non_isolated'
19151918
filename = _testmultiphase.__file__
19161919
loader = ExtensionFileLoader(modname, filename)
@@ -1929,23 +1932,33 @@ def test_multi_init_extension_non_isolated_compat(self):
19291932

19301933
@unittest.skipIf(_testmultiphase is None, "test requires _testmultiphase module")
19311934
def test_multi_init_extension_per_interpreter_gil_compat(self):
1932-
modname = '_test_shared_gil_only'
1933-
filename = _testmultiphase.__file__
1934-
loader = ExtensionFileLoader(modname, filename)
1935-
spec = importlib.util.spec_from_loader(modname, loader)
1936-
module = importlib.util.module_from_spec(spec)
1937-
loader.exec_module(module)
1938-
sys.modules[modname] = module
1939-
1940-
require_extension(module)
1941-
with self.subTest(f'{modname}: isolated, strict'):
1942-
self.check_incompatible_here(modname, filename, isolated=True)
1943-
with self.subTest(f'{modname}: not isolated, strict'):
1944-
self.check_compatible_here(modname, filename,
1945-
strict=True, isolated=False)
1946-
with self.subTest(f'{modname}: not isolated, not strict'):
1947-
self.check_compatible_here(modname, filename,
1948-
strict=False, isolated=False)
1935+
# _test_shared_gil_only:
1936+
# Explicit Py_MOD_MULTIPLE_INTERPRETERS_SUPPORTED (default)
1937+
# and Py_MOD_GIL_NOT_USED
1938+
# _test_no_multiple_interpreter_slot:
1939+
# No Py_mod_multiple_interpreters slot
1940+
# and Py_MOD_GIL_NOT_USED
1941+
for modname in ('_test_shared_gil_only',
1942+
'_test_no_multiple_interpreter_slot'):
1943+
with self.subTest(modname=modname):
1944+
1945+
filename = _testmultiphase.__file__
1946+
loader = ExtensionFileLoader(modname, filename)
1947+
spec = importlib.util.spec_from_loader(modname, loader)
1948+
module = importlib.util.module_from_spec(spec)
1949+
loader.exec_module(module)
1950+
sys.modules[modname] = module
1951+
1952+
require_extension(module)
1953+
with self.subTest(f'{modname}: isolated, strict'):
1954+
self.check_incompatible_here(modname, filename,
1955+
isolated=True)
1956+
with self.subTest(f'{modname}: not isolated, strict'):
1957+
self.check_compatible_here(modname, filename,
1958+
strict=True, isolated=False)
1959+
with self.subTest(f'{modname}: not isolated, not strict'):
1960+
self.check_compatible_here(
1961+
modname, filename, strict=False, isolated=False)
19491962

19501963
def test_python_compat(self):
19511964
module = 'threading'

Modules/_testmultiphase.c

+17
Original file line numberDiff line numberDiff line change
@@ -967,3 +967,20 @@ PyInit__test_shared_gil_only(void)
967967
{
968968
return PyModuleDef_Init(&shared_gil_only_def);
969969
}
970+
971+
972+
static PyModuleDef_Slot no_multiple_interpreter_slot_slots[] = {
973+
{Py_mod_exec, execfunc},
974+
{0, NULL},
975+
};
976+
977+
static PyModuleDef no_multiple_interpreter_slot_def = TEST_MODULE_DEF(
978+
"_test_no_multiple_interpreter_slot",
979+
no_multiple_interpreter_slot_slots,
980+
testexport_methods);
981+
982+
PyMODINIT_FUNC
983+
PyInit__test_no_multiple_interpreter_slot(void)
984+
{
985+
return PyModuleDef_Init(&no_multiple_interpreter_slot_def);
986+
}

0 commit comments

Comments
 (0)