mirror of
https://github.com/python/cpython.git
synced 2025-12-08 06:10:17 +00:00
[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:
parent
d8a72b4c5e
commit
f7d17ac9f8
3 changed files with 211 additions and 2 deletions
|
|
@ -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
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue