File tree 2 files changed +17
-0
lines changed
2 files changed +17
-0
lines changed Original file line number Diff line number Diff line change @@ -36,6 +36,9 @@ def visit_Import(self, node):
36
36
self .imports .append ((node , node .names [0 ].name ))
37
37
38
38
def visit_ImportFrom (self , node ):
39
+ if node .level != 0 :
40
+ # Omit relative imports (local modules).
41
+ return
39
42
self .imports .append ((node , node .module ))
40
43
41
44
Original file line number Diff line number Diff line change @@ -60,3 +60,17 @@ def test_3rd_party_hyphen(self):
60
60
def test_3rd_party_multi_module (self ):
61
61
errors = check ("import pkg_resources" )
62
62
self .assertEqual (len (errors ), 0 )
63
+
64
+ def test_non_top_level_import (self ):
65
+ errors = check ("def function():\n import cat" )
66
+ self .assertEqual (len (errors ), 1 )
67
+ self .assertEqual (
68
+ errors [0 ][2 ],
69
+ "I900 'cat' not listed as a requirement" ,
70
+ )
71
+
72
+ def test_relative_import (self ):
73
+ errors = check ("from . import local" )
74
+ self .assertEqual (len (errors ), 0 )
75
+ errors = check ("from ..local import local" )
76
+ self .assertEqual (len (errors ), 0 )
You can’t perform that action at this time.
0 commit comments