Visitar URL original
Keep module cache entries present during import reordering by youknowdot · Pull Request #8948 · RustPython/RustPython · GitHub
Skip to content
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Keep atomic import regression compatible with modern bootstrap
Run legacy-loader cases when the bootstrap exposes that helper, preserving all four 3.14 paths and the two remaining 3.15 paths. Always retain modern load and exec regressions.

Assisted-by: Codex:model-version-unavailable
  • Loading branch information
youknowdot committed Oct 5, 2026
commit 5dab876b3ee52e75b66fe9ebe494471759803ac3
30 changes: 19 additions & 11 deletions extra_tests/snippets/import_atomic_reorder.py
Original file line number Diff line number Diff line change
Expand Up @@ -77,8 +77,9 @@ def check_trace_presence(bootstrap, mode):
codes = {
bootstrap._exec.__code__,
bootstrap._load_unlocked.__code__,
bootstrap._load_backward_compatible.__code__,
}
if hasattr(bootstrap, "_load_backward_compatible"):
codes.add(bootstrap._load_backward_compatible.__code__)
if hasattr(bootstrap, "_reorder_module"):
codes.add(bootstrap._reorder_module.__code__)

Expand Down Expand Up @@ -185,16 +186,20 @@ def fail_with_entry(module):
)
assert list(sys.modules)[-2:] == [after, name]

class LegacyLoader:
def load_module(self, fullname):
sys.modules[fullname] = None
del sys.modules[fullname]
raise failure
if hasattr(bootstrap, "_load_backward_compatible"):

spec = bootstrap.ModuleSpec(name, LegacyLoader())
sys.modules = original.copy()
raises(RuntimeError, lambda: bootstrap._load_backward_compatible(spec), failure)
assert name not in sys.modules
class LegacyLoader:
def load_module(self, fullname):
sys.modules[fullname] = None
del sys.modules[fullname]
raise failure

spec = bootstrap.ModuleSpec(name, LegacyLoader())
sys.modules = original.copy()
raises(
RuntimeError, lambda: bootstrap._load_backward_compatible(spec), failure
)
assert name not in sys.modules
finally:
sys.modules = original

Expand Down Expand Up @@ -445,7 +450,10 @@ def __del__(self):
if sys.implementation.name == "rustpython":
# Run this before inspecting the new helper so a baseline executable
# fails on the actual pop/set gap, not just a missing private API.
for mode in ("load", "exec", "legacy", "legacy_error"):
modes = ("load", "exec")
if hasattr(bootstrap, "_load_backward_compatible"):
modes += ("legacy", "legacy_error")
for mode in modes:
check_trace_presence(bootstrap, mode)
check_loader_semantics(bootstrap)
if hasattr(bootstrap, "_reorder_module"):
Expand Down