Skip to content

Commit 494e514

Browse files
Fix ModuleNotFoundError when using pylint_django (#7940) (#7941)
Ensure that the import path is fixed up before calling ._astroid_module_checker() so that the pylint_django plugin can successfully import the Django settings module when its checkers are initialized. Closes #7938 (cherry picked from commit 491eef5) Co-authored-by: Daniel Harding <[email protected]>
1 parent 83668de commit 494e514

File tree

2 files changed

+5
-2
lines changed

2 files changed

+5
-2
lines changed

doc/whatsnew/fragments/7938.bugfix

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
Fixes a ``ModuleNotFound`` exception when running pylint on a Django project with the ``pylint_django`` plugin enabled.
2+
3+
Closes #7938

pylint/lint/pylinter.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -690,8 +690,8 @@ def check(self, files_or_modules: Sequence[str] | str) -> None:
690690
data = None
691691

692692
# The contextmanager also opens all checkers and sets up the PyLinter class
693-
with self._astroid_module_checker() as check_astroid_module:
694-
with fix_import_path(files_or_modules):
693+
with fix_import_path(files_or_modules):
694+
with self._astroid_module_checker() as check_astroid_module:
695695
# 4) Get the AST for each FileItem
696696
ast_per_fileitem = self._get_asts(fileitems, data)
697697

0 commit comments

Comments
 (0)