[PATCH 1 of 3 STABLE] demandimportpy3: only use lazy extension loader on Python 3.6+

Gregory Szorc gregory.szorc at gmail.com
Sat Nov 2 19:19:56 UTC 2019


# HG changeset patch
# User Gregory Szorc <gregory.szorc at gmail.com>
# Date 1572720166 25200
#      Sat Nov 02 11:42:46 2019 -0700
# Branch stable
# Node ID 7ebf53ae3eb60566c1580d8209277372dd43e30a
# Parent  842eb05149aca2c201441cafa2a7fda3e06d5b6d
demandimportpy3: only use lazy extension loader on Python 3.6+

There was an inline comment denoting a bug in the lazy extension
loader on Python 3.5 which prevents it from working there. But the
code was not conditional on the Python version.

The result of this was a myriad of failures on Python 3.5 due to
getattr() and friends not working on lazy extension modules.

By making extension modules non-lazy on Python 3.5, we reduce the
number of test failures from 48 to 22 on that Python version.

diff --git a/hgdemandimport/demandimportpy3.py b/hgdemandimport/demandimportpy3.py
--- a/hgdemandimport/demandimportpy3.py
+++ b/hgdemandimport/demandimportpy3.py
@@ -53,9 +53,13 @@ class _lazyloaderex(importlib.util.LazyL
 
 # This is 3.6+ because with Python 3.5 it isn't possible to lazily load
 # extensions. See the discussion in https://bugs.python.org/issue26186 for more.
-_extensions_loader = _lazyloaderex.factory(
-    importlib.machinery.ExtensionFileLoader
-)
+if sys.version_info[0:2] >= (3, 6):
+    _extensions_loader = _lazyloaderex.factory(
+        importlib.machinery.ExtensionFileLoader
+    )
+else:
+    _extensions_loader = importlib.machinery.ExtensionFileLoader
+
 _bytecode_loader = _lazyloaderex.factory(
     importlib.machinery.SourcelessFileLoader
 )


More information about the Mercurial-devel mailing list