# HG changeset patch # User Jason R. Coombs # Date 2022-11-02 13:34:03 # Node ID 7236f11db0c32325b610df4c049d2593574d3a6f # Parent 8a8005025d1c8b6be088ed4a6c483562be14a398 demandimport: ensure lazyloaderex sets loader attributes (issue6725) Adds test capturing missed expectation. diff --git a/hgdemandimport/demandimportpy3.py b/hgdemandimport/demandimportpy3.py --- a/hgdemandimport/demandimportpy3.py +++ b/hgdemandimport/demandimportpy3.py @@ -41,6 +41,10 @@ class _lazyloaderex(importlib.util.LazyL """Make the module load lazily.""" with tracing.log('demandimport %s', module): if _deactivated or module.__name__ in ignores: + # Reset the loader on the module as super() does (issue6725) + module.__spec__.loader = self.loader + module.__loader__ = self.loader + self.loader.exec_module(module) else: super().exec_module(module) diff --git a/tests/test-demandimport.py b/tests/test-demandimport.py --- a/tests/test-demandimport.py +++ b/tests/test-demandimport.py @@ -234,3 +234,11 @@ assert 'ftplib' not in sys.modules zipfileimp = __import__('ftplib', globals(), locals(), ['unknownattr']) assert f(zipfileimp) == "", f(zipfileimp) assert not util.safehasattr(zipfileimp, 'unknownattr') + + +# test deactivation for issue6725 +del sys.modules['telnetlib'] +with demandimport.deactivated(): + import telnetlib +assert telnetlib.__loader__ == telnetlib.__spec__.loader +assert telnetlib.__loader__.get_resource_reader