Patchwork [3,of,8] import-checker: always build a list of imported symbols

login
register
mail settings
Submitter Yuya Nishihara
Date May 14, 2016, 7:33 a.m.
Message ID <c227e9d4e8c137fd1dd6.1463211228@mimosa>
Download mbox | patch
Permalink /patch/15110/
State Accepted
Headers show

Comments

Yuya Nishihara - May 14, 2016, 7:33 a.m.
# HG changeset patch
# User Yuya Nishihara <yuya@tcha.org>
# Date 1463199613 -32400
#      Sat May 14 13:20:13 2016 +0900
# Node ID c227e9d4e8c137fd1dd67ebd6b21aae8dfab68d1
# Parent  f9c6e835b650600d21846e5ce2cabf0ffc53da3c
import-checker: always build a list of imported symbols

The next patch will rely on it.

Patch

diff --git a/contrib/import-checker.py b/contrib/import-checker.py
--- a/contrib/import-checker.py
+++ b/contrib/import-checker.py
@@ -456,15 +456,14 @@  def verify_modern_convention(module, roo
 
             # Direct symbol import is only allowed from certain modules and
             # must occur before non-symbol imports.
+            found = fromlocal(node.module, node.level)
+            if found and found[2]:  # node.module is a package
+                prefix = found[0] + '.'
+                symbols = [n.name for n in node.names
+                           if not fromlocal(prefix + n.name)]
+            else:
+                symbols = [n.name for n in node.names]
             if node.module and node.col_offset == root_col_offset:
-                found = fromlocal(node.module, node.level)
-                if found and found[2]:  # node.module is a package
-                    prefix = found[0] + '.'
-                    symbols = [n.name for n in node.names
-                               if not fromlocal(prefix + n.name)]
-                else:
-                    symbols = [n.name for n in node.names]
-
                 if symbols and fullname not in allowsymbolimports:
                     yield msg('direct symbol import %s from %s',
                               ', '.join(symbols), fullname)