Patchwork [8,of,8] import-checker: print hint to use absolute_import

login
register
mail settings
Submitter Gregory Szorc
Date May 25, 2015, 7:23 p.m.
Message ID <379cecb41e7fb6a1703a.1432581832@vm-ubuntu-main.gateway.sonic.net>
Download mbox | patch
Permalink /patch/9264/
State Rejected
Headers show

Comments

Gregory Szorc - May 25, 2015, 7:23 p.m.
# HG changeset patch
# User Gregory Szorc <gregory.szorc@gmail.com>
# Date 1432581750 25200
#      Mon May 25 12:22:30 2015 -0700
# Node ID 379cecb41e7fb6a1703a5cb7442a9e8016f5a177
# Parent  8daa70ee538105207ece9a23be502aabd26d94e7
import-checker: print hint to use absolute_import

We no longer have mixed imports in the source tree. Mixed imports can
be eliminated by using `from __future__ import absolute_import`. Add
a reference to absolute_import to the emitted error message so people
know they should be using absolute_import.

Patch

diff --git a/contrib/import-checker.py b/contrib/import-checker.py
--- a/contrib/import-checker.py
+++ b/contrib/import-checker.py
@@ -267,9 +267,9 @@  def verify_stdlib_on_own_line(source):
     annoying lib2to3 bug in relative import rewrites:
     http://bugs.python.org/issue19510.
 
     >>> list(verify_stdlib_on_own_line('import sys, foo'))
-    ['mixed imports\\n   stdlib:    sys\\n   relative:  foo']
+    ['mixed imports (use absolute_import)\\n   stdlib:    sys\\n   relative:  foo']
     >>> list(verify_stdlib_on_own_line('import sys, os'))
     []
     >>> list(verify_stdlib_on_own_line('import foo, bar'))
     []
@@ -279,9 +279,11 @@  def verify_stdlib_on_own_line(source):
             from_stdlib = {False: [], True: []}
             for n in node.names:
                 from_stdlib[n.name in stdlib_modules].append(n.name)
             if from_stdlib[True] and from_stdlib[False]:
-                yield ('mixed imports\n   stdlib:    %s\n   relative:  %s' %
+                yield ('mixed imports (use absolute_import)\n'
+                       '   stdlib:    %s\n'
+                       '   relative:  %s' %
                        (', '.join(sorted(from_stdlib[True])),
                         ', '.join(sorted(from_stdlib[False]))))
 
 class CircularImport(Exception):