demandimport: support importing builtins for Python 3
authorGregory Szorc <gregory.szorc@gmail.com>
Sat, 27 Jun 2015 17:31:06 -0700
changeset 25674 5d0847cd1587
parent 25673 fa1f04529775
child 25675 c76e8d14383a
demandimport: support importing builtins for Python 3 __builtin__ was renamed to builtins in Python 3. If importing __builtin__ fails, fall back to importing builtins in order to support Python 3.
mercurial/demandimport.py
--- a/mercurial/demandimport.py	Sat Jun 27 17:29:15 2015 -0700
+++ b/mercurial/demandimport.py	Sat Jun 27 17:31:06 2015 -0700
@@ -26,7 +26,12 @@
 
 import os, sys
 from contextlib import contextmanager
-import __builtin__ as builtins
+
+# __builtin__ in Python 2, builtins in Python 3.
+try:
+    import __builtin__ as builtins
+except ImportError:
+    import builtins
 
 _origimport = __import__