Patchwork [09,of,13,V2,py3,support] check-code: new rule to forbid imports of a.b on the same line as other imports

login
register
mail settings
Submitter Augie Fackler
Date Sept. 20, 2013, 2:23 p.m.
Message ID <1c6293f6b4ce2241d525.1379687027@arthedain.pit.corp.google.com>
Download mbox | patch
Permalink /patch/2557/
State Superseded
Headers show

Comments

Augie Fackler - Sept. 20, 2013, 2:23 p.m.
# HG changeset patch
# User Augie Fackler <raf@durin42.com>
# Date 1379686689 14400
#      Fri Sep 20 10:18:09 2013 -0400
# Node ID 1c6293f6b4ce2241d525ef815e3f37ca4873d6e8
# Parent  77a5a10b01b76a6fc347ec4fe97507cef667ee6b
check-code: new rule to forbid imports of a.b on the same line as other imports

This style of import can trip up 2to3 and cause it to produce invalid
files if one of the imports is supposed to be a relative import. This
prevents that behavior, and in the process exposed a lot of silly
import errors related to the email module.

Patch

diff --git a/contrib/check-code.py b/contrib/check-code.py
--- a/contrib/check-code.py
+++ b/contrib/check-code.py
@@ -162,6 +162,9 @@ 
      "tuple parameter unpacking not available in Python 3+"),
     (r'lambda\s*\(.*,.*\)',
      "tuple parameter unpacking not available in Python 3+"),
+    (r'import (.+,[^.]+\.[^.]+|[^.]+\.[^.]+,)',
+     '2to3 can\'t always rewrite "import qux, foo.bar", '
+     'use "import foo.bar" on its own line instead.'),
     (r'(?<!def)\s+(cmp)\(', "cmp is not available in Python 3+"),
     (r'\breduce\s*\(.*', "reduce is not available in Python 3+"),
     (r'\.has_key\b', "dict.has_key is not available in Python 3+"),