diff --git a/hgdemandimport/__init__.py b/hgdemandimport/__init__.py --- a/hgdemandimport/__init__.py +++ b/hgdemandimport/__init__.py @@ -21,8 +21,9 @@ else: from . import demandimportpy2 as demandimport -# Extensions can add to this list if necessary. -ignore = [ +# Full module names which can't be lazy imported. +# Extensions can add to this set. +IGNORES = { '__future__', '_hashlib', # ImportError during pkg_resources/__init__.py:fixup_namespace_package @@ -55,17 +56,15 @@ '__builtin__', 'builtins', 'urwid.command_map', # for pudb - ] +} _pypy = '__pypy__' in sys.builtin_module_names if _pypy: - ignore.extend([ - # _ctypes.pointer is shadowed by "from ... import pointer" (PyPy 5) - '_ctypes.pointer', - ]) + # _ctypes.pointer is shadowed by "from ... import pointer" (PyPy 5) + IGNORES.add('_ctypes.pointer') -demandimport.init(ignore) +demandimport.init(IGNORES) # Re-export. isenabled = demandimport.isenabled diff --git a/hgdemandimport/demandimportpy2.py b/hgdemandimport/demandimportpy2.py --- a/hgdemandimport/demandimportpy2.py +++ b/hgdemandimport/demandimportpy2.py @@ -162,7 +162,7 @@ _pypy = '__pypy__' in sys.builtin_module_names def _demandimport(name, globals=None, locals=None, fromlist=None, level=-1): - if locals is None or name in ignore or fromlist == ('*',): + if locals is None or name in ignores or fromlist == ('*',): # these cases we can't really delay return _hgextimport(_origimport, name, globals, locals, fromlist, level) elif not fromlist: @@ -209,7 +209,7 @@ # while processing the import statement. return mn = '%s.%s' % (mod.__name__, attr) - if mn in ignore: + if mn in ignores: importfunc = _origimport else: importfunc = _demandmod @@ -273,11 +273,11 @@ return mod -ignore = [] +ignores = set() -def init(ignorelist): - global ignore - ignore = ignorelist +def init(ignoreset): + global ignores + ignores = ignoreset def isenabled(): return builtins.__import__ == _demandimport diff --git a/hgdemandimport/demandimportpy3.py b/hgdemandimport/demandimportpy3.py --- a/hgdemandimport/demandimportpy3.py +++ b/hgdemandimport/demandimportpy3.py @@ -40,7 +40,7 @@ """ def exec_module(self, module): """Make the module load lazily.""" - if _deactivated or module.__name__ in ignore: + if _deactivated or module.__name__ in ignores: self.loader.exec_module(module) else: super().exec_module(module) @@ -62,11 +62,11 @@ (_bytecode_loader, importlib.machinery.BYTECODE_SUFFIXES), ) -ignore = [] +ignores = set() -def init(ignorelist): - global ignore - ignore = ignorelist +def init(ignoreset): + global ignores + ignores = ignoreset def isenabled(): return _makefinder in sys.path_hooks and not _deactivated diff --git a/hgext/convert/bzr.py b/hgext/convert/bzr.py --- a/hgext/convert/bzr.py +++ b/hgext/convert/bzr.py @@ -19,7 +19,7 @@ from . import common # these do not work with demandimport, blacklist -demandimport.ignore.extend([ +demandimport.IGNORES.update([ 'bzrlib.transactions', 'bzrlib.urlutils', 'ElementPath', diff --git a/hgext/highlight/highlight.py b/hgext/highlight/highlight.py --- a/hgext/highlight/highlight.py +++ b/hgext/highlight/highlight.py @@ -11,7 +11,7 @@ from __future__ import absolute_import from mercurial import demandimport -demandimport.ignore.extend(['pkgutil', 'pkg_resources', '__main__']) +demandimport.IGNORES.update(['pkgutil', 'pkg_resources', '__main__']) from mercurial import ( encoding,