This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author vstinner
Recipients brett.cannon, eric.snow, ncoghlan, shihai1991, vstinner
Date 2020-03-24.13:58:13
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1585058293.99.0.210484704215.issue40050@roundup.psfhosted.org>
In-reply-to
Content
Quick & dirty workaround:

diff --git a/Lib/importlib/_bootstrap_external.py b/Lib/importlib/_bootstrap_external.py
index 7353bf9a78..d988552f2d 100644
--- a/Lib/importlib/_bootstrap_external.py
+++ b/Lib/importlib/_bootstrap_external.py
@@ -1620,7 +1620,10 @@ def _setup(_bootstrap_module):
     setattr(self_module, '_thread', thread_module)
 
     # Directly load the _weakref module (needed during bootstrap).
-    weakref_module = _bootstrap._builtin_from_name('_weakref')
+    if '_weakref' not in sys.modules:
+        weakref_module = _bootstrap._builtin_from_name('_weakref')
+    else:
+        weakref_module = sys.modules['_weakref']
     setattr(self_module, '_weakref', weakref_module)
 
     # Directly load the winreg module (needed during bootstrap).


But I think that the issue is larger than just _weakref.

* Maybe the test_importlib should before save/restore the the "Python state" rather than modifying modules
* Maybe module.__spec__ should leak less importlib internals: explicitly clear namespaces? Use static methods? I'm not sure how to do that.
* Remove module.__spec__? ... that would mean rejecting PEP 451 implemented in Python 3.4, that sounds like a major regression :-(
History
Date User Action Args
2020-03-24 13:58:14vstinnersetrecipients: + vstinner, brett.cannon, ncoghlan, eric.snow, shihai1991
2020-03-24 13:58:13vstinnersetmessageid: <1585058293.99.0.210484704215.issue40050@roundup.psfhosted.org>
2020-03-24 13:58:13vstinnerlinkissue40050 messages
2020-03-24 13:58:13vstinnercreate