File tree Expand file tree Collapse file tree 2 files changed +11
-21
lines changed Expand file tree Collapse file tree 2 files changed +11
-21
lines changed Original file line number Diff line number Diff line change @@ -75,29 +75,18 @@ def visit_ImportFrom( # noqa: N802, pylint: disable=invalid-name
75
75
def _add_module (self , modname : str , lineno : int ) -> None :
76
76
if self ._ignore_modules_function (modname ):
77
77
return
78
- path = None
79
- progress = []
80
- modpath = None
81
- for modname_part in modname .split ("." ):
82
- find_spec_result = importlib .util .find_spec (
83
- name = modname_part ,
84
- package = path ,
85
- )
86
-
87
- if find_spec_result is None :
88
- # The component specified at this point is not installed.
89
- break
90
-
91
- modpath = find_spec_result .origin
92
78
93
- # success! we found *something*
94
- progress . append ( modname_part )
95
-
96
- if modpath is None :
97
- # the module doesn't actually appear to exist on disk
79
+ find_spec_result = importlib . util . find_spec (
80
+ name = modname . split ( "." )[ 0 ],
81
+ )
82
+ if find_spec_result is None :
83
+ # The component specified at this point is not installed.
98
84
return
99
85
100
- modname = "." .join (progress )
86
+ modpath = find_spec_result .origin
87
+ assert modpath is not None
88
+ modname = find_spec_result .name
89
+
101
90
if modname not in self ._modules :
102
91
self ._modules [modname ] = FoundModule (
103
92
modname = modname ,
Original file line number Diff line number Diff line change @@ -45,7 +45,8 @@ def test_found_module() -> None:
45
45
("from pathlib import Path" , ["pathlib" ]),
46
46
("from string import hexdigits" , ["string" ]),
47
47
("import urllib.request" , ["urllib" ]),
48
- ("import spam" , []), # don't break because bad programmer
48
+ # don't break because bad programmer imported the file we are in
49
+ ("import spam" , []),
49
50
("from .foo import bar" , []), # don't break on relative imports
50
51
("from . import baz" , []),
51
52
],
You can’t perform that action at this time.
0 commit comments