[PATCH 1 of 2] demandimport: alias __builtin__ as builtins
Gregory Szorc
gregory.szorc at gmail.com
Sun Jun 28 00:31:38 UTC 2015
# HG changeset patch
# User Gregory Szorc <gregory.szorc at gmail.com>
# Date 1435451355 25200
# Sat Jun 27 17:29:15 2015 -0700
# Node ID 9f0cea1d292415d264798752fdc5bbe658b9b5e0
# Parent ff5172c830022b64cc5bd1bae36b2276e9dc6e5d
demandimport: alias __builtin__ as builtins
Python 3 renamed the __builtin__ module to builtins. In preparation for
supporting Python 3, alias the imported module as "builtins."
diff --git a/mercurial/demandimport.py b/mercurial/demandimport.py
--- a/mercurial/demandimport.py
+++ b/mercurial/demandimport.py
@@ -23,10 +23,11 @@ These imports will not be delayed:
from a import *
b = __import__(a)
'''
-import __builtin__, os, sys
+import os, sys
from contextlib import contextmanager
+import __builtin__ as builtins
_origimport = __import__
nothing = object()
@@ -35,9 +36,9 @@ try:
# Python 3 doesn't have relative imports nor level -1.
level = -1
if sys.version_info[0] >= 3:
level = 0
- _origimport(__builtin__.__name__, {}, {}, None, level)
+ _origimport(builtins.__name__, {}, {}, None, level)
except TypeError: # no level argument
def _import(name, globals, locals, fromlist, level):
"call _origimport with no level argument"
return _origimport(name, globals, locals, fromlist)
@@ -170,18 +171,18 @@ ignore = [
'distutils.msvc9compiler'
]
def isenabled():
- return __builtin__.__import__ == _demandimport
+ return builtins.__import__ == _demandimport
def enable():
"enable global demand-loading of modules"
if os.environ.get('HGDEMANDIMPORT') != 'disable':
- __builtin__.__import__ = _demandimport
+ builtins.__import__ = _demandimport
def disable():
"disable global demand-loading of modules"
- __builtin__.__import__ = _origimport
+ builtins.__import__ = _origimport
@contextmanager
def deactivated():
"context manager for disabling demandimport in 'with' blocks"
More information about the Mercurial-devel
mailing list