Skip to content

Commit

Permalink
Avoid search paths for ImportChecker when possible
Browse files Browse the repository at this point in the history
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 call to it more uniform and opens up the possibility of effective
caching.

Refs pylint-dev#9310.
  • Loading branch information
crazybolillo committed May 4, 2024
1 parent 3c8be8e commit c2b5807
Showing 1 changed file with 6 additions and 3 deletions.
9 changes: 6 additions & 3 deletions pylint/checkers/imports.py
Original file line number Diff line number Diff line change
Expand Up @@ -1045,9 +1045,12 @@ def _add_imported_module(self, node: ImportNode, importedmodname: str) -> None:
base = os.path.splitext(os.path.basename(module_file))[0]

try:
importedmodname = astroid.modutils.get_module_part(
importedmodname, module_file
)
if isinstance(node, nodes.ImportFrom) and node.level:
importedmodname = astroid.modutils.get_module_part(
importedmodname, module_file
)
else:
importedmodname = astroid.modutils.get_module_part(importedmodname)
except ImportError:
pass

Expand Down

0 comments on commit c2b5807

Please sign in to comment.