Mercurial > hg
diff tests/test-module-imports.t @ 26965:1fa66d3ad28d
import-checker: reset context to verify convention in function scope
I got the following error by rewriting hgweb/webcommands.py to use
absolute_import. It is false-positive because the import line appears in
"help" function:
hgweb/webcommands.py:1297: higher-level import should come first: mercurial
This patch makes the import checker aware of the function scope and apply
rules recursively.
author | Yuya Nishihara <yuya@tcha.org> |
---|---|
date | Sun, 01 Nov 2015 17:42:03 +0900 |
parents | 5abba2c92da3 |
children | 69308357ecd1 |
line wrap: on
line diff
--- a/tests/test-module-imports.t Sun Nov 01 00:37:22 2015 +0900 +++ b/tests/test-module-imports.t Sun Nov 01 17:42:03 2015 +0900 @@ -74,6 +74,17 @@ > from . import levelpriority # should not cause cycle > EOF + $ cat > testpackage/subpackage/localimport.py << EOF + > from __future__ import absolute_import + > from . import foo + > def bar(): + > # should not cause "higher-level import should come first" + > from .. import unsorted + > # but other errors should be detected + > from .. import more + > import testpackage.subpackage.levelpriority + > EOF + $ cat > testpackage/sortedentries.py << EOF > from __future__ import absolute_import > from . import ( @@ -105,6 +116,8 @@ testpackage/sortedentries.py:2: imports from testpackage not lexically sorted: bar < foo testpackage/stdafterlocal.py:3: stdlib import follows local import: os 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 from testpackage.unsorted testpackage/unsorted.py:3: imports not lexically sorted: os < sys [1]