Skip to content

bpo-40173: Remove redundant import module of import_fresh_module() #19390

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
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
4 changes: 3 additions & 1 deletion Lib/test/support/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -240,8 +240,10 @@ def _save_and_remove_module(name, orig_modules):
"""
# try to import the module and raise an error if it can't be imported
if name not in sys.modules:
orig_modules = sys.modules.copy()
__import__(name)
del sys.modules[name]
sys.modules.clear()
sys.modules.update(orig_modules)
Comment on lines +245 to +246
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I considered this option, but some modules can not support re-importing. So it is safer to restore only explicitly mentioned modules and their submodules.
See #28654.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh, sorry, Serhiy. I missed your PR :(

for modname in list(sys.modules):
if modname == name or modname.startswith(name + '.'):
orig_modules[modname] = sys.modules[modname]
Expand Down