Bug 1559975: Don't require absolute import future if we don't have any imports r=ahal
☠☠ backed out by 18f3d786c289 ☠ ☠
authorChris AtLee <catlee@mozilla.com>
Mon, 24 Jun 2019 21:20:43 +0000
changeset 543042 0560cf7df7dc9ca8cb2a988658a91632ad406718
parent 543041 4cb64ca524e716209f18079bb81649be8231a79e
child 543043 0c36f78c971a8cfd91a5b9c039b520027cb7a73c
push id2131
push userffxbld-merge
push dateMon, 26 Aug 2019 18:30:20 +0000
treeherdermozilla-release@b19ffb3ca153 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersahal
bugs1559975
milestone69.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1559975: Don't require absolute import future if we don't have any imports r=ahal Differential Revision: https://phabricator.services.mozilla.com/D35341
tools/lint/python/check_compat.py
--- a/tools/lint/python/check_compat.py
+++ b/tools/lint/python/check_compat.py
@@ -33,31 +33,36 @@ def check_compat_py2(f):
 
     # Ignore empty or un-parseable files.
     if not root or not root.body:
         return
 
     futures = set()
     haveprint = False
     future_lineno = 1
+    may_have_relative_imports = False
     for node in ast.walk(root):
         if isinstance(node, ast.ImportFrom):
             if node.module == '__future__':
                 future_lineno = node.lineno
                 futures |= set(n.name for n in node.names)
+            else:
+                may_have_relative_imports = True
+        elif isinstance(node, ast.Import):
+            may_have_relative_imports = True
         elif isinstance(node, ast.Print):
             haveprint = True
 
     err = {
         'path': f,
         'lineno': future_lineno,
         'column': 1,
     }
 
-    if 'absolute_import' not in futures:
+    if 'absolute_import' not in futures and may_have_relative_imports:
         err['rule'] = 'require absolute_import'
         err['message'] = 'Missing from __future__ import absolute_import'
         print(json.dumps(err))
 
     if haveprint and 'print_function' not in futures:
         err['rule'] = 'require print_function'
         err['message'] = 'Missing from __future__ import print_function'
         print(json.dumps(err))