Mercurial > hg-stable
diff mercurial/__init__.py @ 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 | 0906b85bf222 |
children | 942051a29fb6 |
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):