Skip to content

Commit b19b94b

Browse files
authored
Avoid search paths for ImportChecker when possible (#9595)
* Avoid search paths for ImportChecker when possible If possible it is desirable to look for modules with no context file as it results in no search paths being given to astroid's find_spec(). This makes calls to it more uniform and opens up the possibility of effective caching. Refs #9310.
1 parent c864cd4 commit b19b94b

File tree

2 files changed

+10
-3
lines changed

2 files changed

+10
-3
lines changed
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
ImportChecker's logic has been modified to avoid context files when possible. This makes it possible
2+
to cache module searches on astroid and reduce execution times.
3+
4+
Refs #9310.

pylint/checkers/imports.py

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1045,9 +1045,12 @@ def _add_imported_module(self, node: ImportNode, importedmodname: str) -> None:
10451045
base = os.path.splitext(os.path.basename(module_file))[0]
10461046

10471047
try:
1048-
importedmodname = astroid.modutils.get_module_part(
1049-
importedmodname, module_file
1050-
)
1048+
if isinstance(node, nodes.ImportFrom) and node.level:
1049+
importedmodname = astroid.modutils.get_module_part(
1050+
importedmodname, module_file
1051+
)
1052+
else:
1053+
importedmodname = astroid.modutils.get_module_part(importedmodname)
10511054
except ImportError:
10521055
pass
10531056

0 commit comments

Comments
 (0)