changeset 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
files hgdemandimport/demandimportpy2.py tests/test-check-py3-compat.t
diffstat 2 files changed, 6 insertions(+), 14 deletions(-) [+]
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)
--- a/tests/test-check-py3-compat.t	Sun Jul 16 17:16:32 2017 +0900
+++ b/tests/test-check-py3-compat.t	Sun Jul 16 17:19:22 2017 +0900
@@ -3,8 +3,9 @@
   $ . "$TESTDIR/helpers-testrepo.sh"
   $ cd "$TESTDIR"/..
 
-  $ testrepohg files 'set:(**.py)' | sed 's|\\|/|g' \
-  > | xargs $PYTHON contrib/check-py3-compat.py
+  $ testrepohg files 'set:(**.py)' \
+  > -X hgdemandimport/demandimportpy2.py \
+  > | sed 's|\\|/|g' | xargs $PYTHON contrib/check-py3-compat.py
   contrib/python-zstandard/setup.py not using absolute_import
   contrib/python-zstandard/setup_zstd.py not using absolute_import
   contrib/python-zstandard/tests/common.py not using absolute_import
@@ -24,6 +25,7 @@
 
 #if py3exe
   $ testrepohg files 'set:(**.py) - grep(pygments)' \
+  > -X hgdemandimport/demandimportpy2.py \
   > -X hgext/fsmonitor/pywatchman \
   > | sed 's|\\|/|g' | xargs $PYTHON3 contrib/check-py3-compat.py \
   > | sed 's/[0-9][0-9]*)$/*)/'