Patchwork [2,of,8,demandimport-py3] import-checker: add a way to directly import certain symbols

login
register
mail settings
Submitter Siddharth Agarwal
Date May 21, 2017, 8:47 p.m.
Message ID <2fc0a078b9f1dfa17420.1495399677@devvm31800.prn1.facebook.com>
Download mbox | patch
Permalink /patch/20806/
State Accepted
Headers show

Comments

Siddharth Agarwal - May 21, 2017, 8:47 p.m.
# HG changeset patch
# User Siddharth Agarwal <sid0@fb.com>
# Date 1495393741 25200
#      Sun May 21 12:09:01 2017 -0700
# Node ID 2fc0a078b9f1dfa17420b90895d02d4574618c11
# Parent  5e82c2bdd3331c097629feb7108ec6b4975384e7
import-checker: add a way to directly import certain symbols

We'll use this for the 'demandimport' symbol in an upcoming patch.

Patch

diff --git a/contrib/import-checker.py b/contrib/import-checker.py
--- a/contrib/import-checker.py
+++ b/contrib/import-checker.py
@@ -24,6 +24,9 @@  allowsymbolimports = (
     'mercurial.node',
 )
 
+# Whitelist of symbols that can be directly imported.
+directsymbols = ()
+
 # Modules that must be aliased because they are commonly confused with
 # common variables and can create aliasing and readability issues.
 requirealias = {
@@ -464,10 +467,11 @@  def verify_modern_convention(module, roo
             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)]
+                symbols = (n.name for n in node.names
+                           if not fromlocal(prefix + n.name))
             else:
-                symbols = [n.name for n in node.names]
+                symbols = (n.name for n in node.names)
+            symbols = [sym for sym in symbols if sym not in directsymbols]
             if node.module and node.col_offset == root_col_offset:
                 if symbols and fullname not in allowsymbolimports:
                     yield msg('direct symbol import %s from %s',