Mercurial > hg
diff hgdemandimport/demandimportpy2.py @ 33530:05e3fa254b6b
demandimport: drop Py3 workarounds from Py2 implementation
author | Yuya Nishihara <yuya@tcha.org> |
---|---|
date | Sun, 16 Jul 2017 17:19:22 +0900 |
parents | ded3ebae8779 |
children | 9cbbf9118c6c |
line wrap: on
line diff
--- a/hgdemandimport/demandimportpy2.py Sun Jul 16 17:16:32 2017 +0900 +++ b/hgdemandimport/demandimportpy2.py Sun Jul 16 17:19:22 2017 +0900 @@ -26,27 +26,17 @@ from __future__ import absolute_import +import __builtin__ as builtins import contextlib import os import sys -# __builtin__ in Python 2, builtins in Python 3. -try: - import __builtin__ as builtins -except ImportError: - import builtins - contextmanager = contextlib.contextmanager _origimport = __import__ nothing = object() -# Python 3 doesn't have relative imports nor level -1. -level = -1 -if sys.version_info[0] >= 3: - level = 0 - def _hgextimport(importfunc, name, globals, *args, **kwargs): try: return importfunc(name, globals, *args, **kwargs) @@ -172,7 +162,7 @@ _pypy = '__pypy__' in sys.builtin_module_names -def _demandimport(name, globals=None, locals=None, fromlist=None, level=level): +def _demandimport(name, globals=None, locals=None, fromlist=None, level=-1): if locals is None or name in ignore or fromlist == ('*',): # these cases we can't really delay return _hgextimport(_origimport, name, globals, locals, fromlist, level)