changeset 32463:397e3a2e9347

python3: allow hgloader to work with lazy loaders Don't clobber the loader returned from find_spec. This brings `hg version` down from 0.27 seconds to 0.17.
author Siddharth Agarwal <sid0@fb.com>
date Sun, 21 May 2017 13:26:17 -0700
parents b4810bf95c03
children 06aa645e2372
files mercurial/__init__.py
diffstat 1 files changed, 8 insertions(+), 1 deletions(-) [+]
line wrap: on
line diff
--- a/mercurial/__init__.py	Sun May 21 12:51:01 2017 -0700
+++ b/mercurial/__init__.py	Sun May 21 13:26:17 2017 -0700
@@ -53,7 +53,14 @@
 
             # TODO need to support loaders from alternate specs, like zip
             # loaders.
-            spec.loader = hgloader(spec.name, spec.origin)
+            loader = hgloader(spec.name, spec.origin)
+            # Can't use util.safehasattr here because that would require
+            # importing util, and we're in import code.
+            if hasattr(spec.loader, 'loader'): # hasattr-py3-only
+                # This is a nested loader (maybe a lazy loader?)
+                spec.loader.loader = loader
+            else:
+                spec.loader = loader
             return spec
 
     def replacetokens(tokens, fullname):