[3.14] gh-140011: Delete importdl assertion that prevents importing embedded modules from packages (GH-141605) (#141986)

gh-140011: Delete importdl assertion that prevents importing embedded modules from packages (GH-141605)

(cherry picked from commit 27f62eb711)
This commit is contained in:
Itamar Oren 2025-11-28 23:30:57 -08:00 committed by GitHub
parent d8a72b4c5e
commit f7d17ac9f8
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 211 additions and 2 deletions

View file

@ -239,6 +239,26 @@ def test_repeated_init_and_inittab(self):
lines = "\n".join(lines) + "\n"
self.assertEqual(out, lines)
def test_inittab_submodule_multiphase(self):
out, err = self.run_embedded_interpreter("test_inittab_submodule_multiphase")
self.assertEqual(err, "")
self.assertEqual(out,
"<module 'mp_pkg.mp_submod' (built-in)>\n"
"<module 'mp_pkg.mp_submod' (built-in)>\n"
"Hello from sub-module\n"
"mp_pkg.mp_submod.mp_submod_exec_slot_ran='yes'\n"
"mp_pkg.mp_pkg_exec_slot_ran='yes'\n"
)
def test_inittab_submodule_singlephase(self):
out, err = self.run_embedded_interpreter("test_inittab_submodule_singlephase")
self.assertEqual(self._nogil_filtered_err(err, "sp_pkg"), "")
self.assertEqual(out,
"<module 'sp_pkg.sp_submod' (built-in)>\n"
"<module 'sp_pkg.sp_submod' (built-in)>\n"
"Hello from sub-module\n"
)
def test_forced_io_encoding(self):
# Checks forced configuration of embedded interpreter IO streams
env = dict(os.environ, PYTHONIOENCODING="utf-8:surrogateescape")
@ -516,6 +536,24 @@ def test_getargs_reset_static_parser(self):
out, err = self.run_embedded_interpreter("test_repeated_init_exec", code)
self.assertEqual(out, '1\n2\n3\n' * INIT_LOOPS)
@staticmethod
def _nogil_filtered_err(err: str, mod_name: str) -> str:
if not support.Py_GIL_DISABLED:
return err
# the test imports a singlephase init extension, so it emits a warning
# under the free-threaded build
expected_runtime_warning = (
"RuntimeWarning: The global interpreter lock (GIL)"
f" has been enabled to load module '{mod_name}'"
)
filtered_err_lines = [
line
for line in err.strip().splitlines()
if expected_runtime_warning not in line
]
return "\n".join(filtered_err_lines)
def config_dev_mode(preconfig, config):
preconfig['allocator'] = PYMEM_ALLOCATOR_DEBUG