Mercurial > hg
changeset 28330:f3fb24e36d61
import-checker: report local with stdlib late warning
Without this, developers have to figure it out on their own
author | timeless <timeless@mozdev.org> |
---|---|
date | Wed, 02 Mar 2016 15:38:54 +0000 |
parents | e69343e80aec |
children | 2874db5462d3 |
files | contrib/import-checker.py tests/test-check-module-imports.t |
diffstat | 2 files changed, 6 insertions(+), 5 deletions(-) [+] |
line wrap: on
line diff
--- a/contrib/import-checker.py Thu Mar 03 23:11:33 2016 -0800 +++ b/contrib/import-checker.py Wed Mar 02 15:38:54 2016 +0000 @@ -366,7 +366,7 @@ fromlocal = fromlocalfunc(module, localmods) # Whether a local/non-stdlib import has been performed. - seenlocal = False + seenlocal = None # Whether a relative, non-symbol import has been seen. seennonsymbolrelative = False # The last name to be imported (for sorting). @@ -403,10 +403,11 @@ # stdlib imports should be before local imports. stdlib = name in stdlib_modules if stdlib and seenlocal and node.col_offset == root_col_offset: - yield msg('stdlib import follows local import: %s', name) + yield msg('stdlib import "%s" follows local import: %s', + name, seenlocal) if not stdlib: - seenlocal = True + seenlocal = name # Import of sibling modules should use relative imports. topname = name.split('.')[0] @@ -437,7 +438,7 @@ if not fullname or fullname in stdlib_modules: yield msg('relative import of stdlib module') else: - seenlocal = True + seenlocal = fullname # Direct symbol import is only allowed from certain modules and # must occur before non-symbol imports.
--- a/tests/test-check-module-imports.t Thu Mar 03 23:11:33 2016 -0800 +++ b/tests/test-check-module-imports.t Wed Mar 02 15:38:54 2016 +0000 @@ -125,7 +125,7 @@ testpackage/relativestdlib.py:2: relative import of stdlib module testpackage/requirerelative.py:2: import should be relative: testpackage.unsorted testpackage/sortedentries.py:2: imports from testpackage not lexically sorted: bar < foo - testpackage/stdafterlocal.py:3: stdlib import follows local import: os + testpackage/stdafterlocal.py:3: stdlib import "os" follows local import: testpackage 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