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
Fix import_helper.module_restored().
  • Loading branch information
ericsnowcurrently committed Apr 30, 2025
commit a135db8c2558b319f222caadebd9b4d3911b7293
6 changes: 3 additions & 3 deletions Lib/test/support/import_helper.py
Original file line number Diff line number Diff line change
Expand Up @@ -338,8 +338,8 @@ def ensure_lazy_imports(imported_module, modules_to_block):
@contextlib.contextmanager
def module_restored(name):
"""A context manager that restores a module to the original state."""
missing = name in sys.modules
orig = sys.modules.get(name)
missing = object()
orig = sys.modules.get(name, missing)
if orig is None:
mod = importlib.import_module(name)
else:
Expand All @@ -349,7 +349,7 @@ def module_restored(name):
try:
yield mod
finally:
if missing:
if orig is missing:
sys.modules.pop(name, None)
else:
sys.modules[name] = orig
Expand Down