diff --git a/contrib/import-checker.py b/contrib/import-checker.py --- a/contrib/import-checker.py +++ b/contrib/import-checker.py @@ -499,7 +499,8 @@ seenlocal = fullname # Direct symbol import is only allowed from certain modules and - # must occur before non-symbol imports. + # must occur before non-symbol imports, or the symbol itself is a + # local module. found = fromlocal(node.module, node.level) if found and found[2]: # node.module is a package prefix = found[0] + '.' @@ -509,7 +510,9 @@ 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: + if (symbols and fullname not in allowsymbolimports + and fullname not in localmods + and fullname + '.__init__' not in localmods): yield msg('direct symbol import %s from %s', ', '.join(symbols), fullname) diff --git a/tests/test-imports-checker.t b/tests/test-imports-checker.t --- a/tests/test-imports-checker.t +++ b/tests/test-imports-checker.t @@ -129,8 +129,6 @@ testpackage/importalias.py:2: ui module must be "as" aliased to uimod testpackage/importfromalias.py:2: ui from testpackage must be "as" aliased to uimod testpackage/importfromrelative.py:2: import should be relative: testpackage.unsorted - testpackage/importfromrelative.py:2: direct symbol import foo from testpackage.unsorted - testpackage/importsymbolfromsub.py:2: direct symbol import nonmodule from testpackage.subpackage testpackage/latesymbolimport.py:3: symbol import follows non-symbol import: mercurial.node testpackage/multiple.py:2: multiple imported names: os, sys testpackage/multiplegroups.py:3: multiple "from . import" statements @@ -141,7 +139,6 @@ testpackage/subpackage/levelpriority.py:3: higher-level import should come first: testpackage testpackage/subpackage/localimport.py:7: multiple "from .. import" statements testpackage/subpackage/localimport.py:8: import should be relative: testpackage.subpackage.levelpriority - testpackage/symbolimport.py:2: direct symbol import foo from testpackage.unsorted testpackage/unsorted.py:3: imports not lexically sorted: os < sys testpackage2/latesymbolimport.py:3: symbol import follows non-symbol import: mercurial.node [1]