Skip to content

Commit a135db8

Browse files
Fix import_helper.module_restored().
1 parent bf0013c commit a135db8

File tree

1 file changed

+3
-3
lines changed

1 file changed

+3
-3
lines changed

Lib/test/support/import_helper.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -338,8 +338,8 @@ def ensure_lazy_imports(imported_module, modules_to_block):
338338
@contextlib.contextmanager
339339
def module_restored(name):
340340
"""A context manager that restores a module to the original state."""
341-
missing = name in sys.modules
342-
orig = sys.modules.get(name)
341+
missing = object()
342+
orig = sys.modules.get(name, missing)
343343
if orig is None:
344344
mod = importlib.import_module(name)
345345
else:
@@ -349,7 +349,7 @@ def module_restored(name):
349349
try:
350350
yield mod
351351
finally:
352-
if missing:
352+
if orig is missing:
353353
sys.modules.pop(name, None)
354354
else:
355355
sys.modules[name] = orig

0 commit comments

Comments
 (0)