Skip to content

Commit 491eef5

Browse files
authored
Fix ModuleNotFoundError when using pylint_django (#7940)
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
1 parent 5a93635 commit 491eef5

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
@@ -697,8 +697,8 @@ def check(self, files_or_modules: Sequence[str] | str) -> None:
697697
data = None
698698

699699
# The contextmanager also opens all checkers and sets up the PyLinter class
700-
with self._astroid_module_checker() as check_astroid_module:
701-
with fix_import_path(files_or_modules):
700+
with fix_import_path(files_or_modules):
701+
with self._astroid_module_checker() as check_astroid_module:
702702
# 4) Get the AST for each FileItem
703703
ast_per_fileitem = self._get_asts(fileitems, data)
704704

0 commit comments

Comments
 (0)