comparison 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
comparison
equal deleted inserted replaced
26964:5abba2c92da3 26965:1fa66d3ad28d
72 $ cat > testpackage/subpackage/__init__.py << EOF 72 $ cat > testpackage/subpackage/__init__.py << EOF
73 > from __future__ import absolute_import 73 > from __future__ import absolute_import
74 > from . import levelpriority # should not cause cycle 74 > from . import levelpriority # should not cause cycle
75 > EOF 75 > EOF
76 76
77 $ cat > testpackage/subpackage/localimport.py << EOF
78 > from __future__ import absolute_import
79 > from . import foo
80 > def bar():
81 > # should not cause "higher-level import should come first"
82 > from .. import unsorted
83 > # but other errors should be detected
84 > from .. import more
85 > import testpackage.subpackage.levelpriority
86 > EOF
87
77 $ cat > testpackage/sortedentries.py << EOF 88 $ cat > testpackage/sortedentries.py << EOF
78 > from __future__ import absolute_import 89 > from __future__ import absolute_import
79 > from . import ( 90 > from . import (
80 > foo, 91 > foo,
81 > bar, 92 > bar,
103 testpackage/relativestdlib.py:2: relative import of stdlib module 114 testpackage/relativestdlib.py:2: relative import of stdlib module
104 testpackage/requirerelative.py:2: import should be relative: testpackage.unsorted 115 testpackage/requirerelative.py:2: import should be relative: testpackage.unsorted
105 testpackage/sortedentries.py:2: imports from testpackage not lexically sorted: bar < foo 116 testpackage/sortedentries.py:2: imports from testpackage not lexically sorted: bar < foo
106 testpackage/stdafterlocal.py:3: stdlib import follows local import: os 117 testpackage/stdafterlocal.py:3: stdlib import follows local import: os
107 testpackage/subpackage/levelpriority.py:3: higher-level import should come first: testpackage 118 testpackage/subpackage/levelpriority.py:3: higher-level import should come first: testpackage
119 testpackage/subpackage/localimport.py:7: multiple "from .. import" statements
120 testpackage/subpackage/localimport.py:8: import should be relative: testpackage.subpackage.levelpriority
108 testpackage/symbolimport.py:2: direct symbol import from testpackage.unsorted 121 testpackage/symbolimport.py:2: direct symbol import from testpackage.unsorted
109 testpackage/unsorted.py:3: imports not lexically sorted: os < sys 122 testpackage/unsorted.py:3: imports not lexically sorted: os < sys
110 [1] 123 [1]
111 124
112 $ cd "$TESTDIR"/.. 125 $ cd "$TESTDIR"/..