From eb2fdc6f488d1a1d4b0cf02e9a8cf03ab33f9d23 Mon Sep 17 00:00:00 2001 From: "Jason R. Coombs" Date: Sun, 28 Dec 2014 15:42:40 -0500 Subject: Extract function for _clear_modules, encapsulating the need for the module names to be greedily evaluated before removing them. --- setuptools/sandbox.py | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) (limited to 'setuptools/sandbox.py') diff --git a/setuptools/sandbox.py b/setuptools/sandbox.py index e958f912..f4f9dfec 100755 --- a/setuptools/sandbox.py +++ b/setuptools/sandbox.py @@ -98,13 +98,18 @@ def save_modules(): finally: sys.modules.update(saved) # remove any modules imported since - del_modules = [ + del_modules = ( mod_name for mod_name in sys.modules if mod_name not in saved # exclude any encodings modules. See #285 and not mod_name.startswith('encodings.') - ] - list(map(sys.modules.__delitem__, del_modules)) + ) + _clear_modules(del_modules) + + +def _clear_modules(module_names): + for mod_name in list(module_names): + del sys.modules[mod_name] @contextlib.contextmanager @@ -151,8 +156,8 @@ def hide_setuptools(): necessary to avoid issues such as #315 where setuptools upgrading itself would fail to find a function declared in the metadata. """ - modules = list(filter(_is_setuptools_module, sys.modules)) - list(map(sys.modules.__delitem__, modules)) + modules = filter(_is_setuptools_module, sys.modules) + _clear_modules(modules) def run_setup(setup_script, args): -- cgit v1.2.1