Bug 1559975: Don't require absolute import future if we don't have any imports r=ahal
authorChris AtLee <catlee@mozilla.com>
Wed, 26 Jun 2019 23:06:47 +0000
changeset 543233 f3a2be3755d103c853efc6eb3c57e5dc4ad62857
parent 543232 cbc5e1529a0c8c4b3f03ee8af70eb8ca9a12f311
child 543234 8fa4afaadbd0234d6b70260197ff8c825b4d20f7
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))