8000 [3.13] gh-129405: Fix doc for Py_mod_multiple_interpreters default, a… · python/cpython@d71b167 · GitHub
[go: up one dir, main page]

Skip to content

Commit d71b167

Browse files
[3.13] gh-129405: Fix doc for Py_mod_multiple_interpreters default, and add test (GH-129406) (GH-130507)
(cherry picked from commit fc8d2cb) Co-authored-by: Petr Viktorin <encukou@gmail.com>
1 parent 10dd972 commit d71b167

File tree

3 files changed

+47
-14
lines changed

3 files changed

+47
-14
lines changed

Doc/c-api/module.rst

Lines changed: 1 addition & 1 deletion
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

Lines changed: 28 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -2404,8 +2404,10 @@ def test_single_init_extension_compat(self):
24042404

24052405
@unittest.skipIf(_testmultiphase is None, "test requires _testmultiphase module")
24062406
def test_multi_init_extension_compat(self):
2407+
# Module with Py_MOD_PER_INTERPRETER_GIL_SUPPORTED
24072408
module = '_testmultiphase'
24082409
require_extension(module)
2410+
24092411
if not Py_GIL_DISABLED:
24102412
with self.subTest(f'{module}: not strict'):
24112413
self.check_compatible_here(module, strict=False)
@@ -2416,6 +2418,8 @@ def test_multi_init_extension_compat(self):
24162418

24172419
@unittest.skipIf(_testmultiphase is None, "test requires _testmultiphase module")
24182420
def test_multi_init_extension_non_isolated_compat(self):
2421+
# Module with Py_MOD_MULTIPLE_INTERPRETERS_NOT_SUPPORTED
2422+
# and Py_MOD_GIL_NOT_USED
24192423
modname = '_test_non_isolated'
24202424
filename = _testmultiphase.__file__
24212425
module = import_extension_from_file(modname, filename)
@@ -2431,20 +2435,31 @@ def test_multi_init_extension_non_isolated_compat(self):
24312435

24322436
@unittest.skipIf(_testmultiphase is None, "test requires _testmultiphase module")
24332437
def test_multi_init_extension_per_interpreter_gil_compat(self):
2434-
modname = '_test_shared_gil_only'
2435-
filename = _testmultiphase.__file__
2436-
module = import_extension_from_file(modname, filename)
24372438

2438-
require_extension(module)
2439-
with self.subTest(f'{modname}: isolated, strict'):
2440-
self.check_incompatible_here(modname, filename, isolated=True)
2441-
with self.subTest(f'{modname}: not isolated, strict'):
2442-
self.check_compatible_here(modname, filename,
2443-
strict=True, isolated=False)
2444-
if not Py_GIL_DISABLED:
2445-
with self.subTest(f'{modname}: not isolated, not strict'):
2446-
self.check_compatible_here(modname, filename,
2447-
strict=False, isolated=False)
2439+
# _test_shared_gil_only:
2440+
# Explicit Py_MOD_MULTIPLE_INTERPRETERS_SUPPORTED (default)
2441+
# and Py_MOD_GIL_NOT_USED
2442+
# _test_no_multiple_interpreter_slot:
2443+
# No Py_mod_multiple_interpreters slot
2444+
# and Py_MOD_GIL_NOT_USED
2445+
for modname in ('_test_shared_gil_only',
2446+
'_test_no_multiple_interpreter_slot'):
2447+
with self.subTest(modname=modname):
2448+
2449+
filename = _testmultiphase.__file__
2450+
module = import_extension_from_file(modname, filename)
2451+
2452+
require_extension(module)
2453+
with self.subTest(f'{modname}: isolated, strict'):
2454+
self.check_incompatible_here(modname, filename,
2455+
isolated=True)
2456+
with self.subTest(f'{modname}: not isolated, strict'):
2457+
self.check_compatible_here(modname, filename,
2458+
strict=True, isolated=False)
2459+
if not Py_GIL_DISABLED:
2460+
with self.subTest(f'{modname}: not isolated, not strict'):
2461+
self.check_compatible_here(
2462+
modname, filename, strict=False, isolated=False)
24482463

24492464
@unittest.skipIf(_testinternalcapi is None, "requires _testinternalcapi")
24502465
def test_python_compat(self):

Modules/_testmultiphase.c

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -969,3 +969,21 @@ PyInit__test_shared_gil_only(void)
969969
{
970970
return PyModuleDef_Init(&shared_gil_only_def);
971971
}
972+
973+
974+
static PyModuleDef_Slot no_multiple_interpreter_slot_slots[] = {
975+
{Py_mod_exec, execfunc},
976+
{Py_mod_gil, Py_MOD_GIL_NOT_USED},
977+
{0, NULL},
978+
};
979+
980+
static PyModuleDef no_multiple_interpreter_slot_def = TEST_MODULE_DEF(
981+
"_test_no_multiple_interpreter_slot",
982+
no_multiple_interpreter_slot_slots,
983+
testexport_methods);
984+
985+
PyMODINIT_FUNC
986+
PyInit__test_no_multiple_interpreter_slot(void)
987+
{
988+
return PyModuleDef_Init(&no_multiple_interpreter_slot_def);
989+
}

0 commit comments

Comments
 (0)
0