Skip to content

Commit

Permalink
Fix ModuleNotFoundError when using pylint_django (#7940) (#7941)
Browse files Browse the repository at this point in the history
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 <dharding@living180.net>
  • Loading branch information
github-actions[bot] and living180 committed Dec 14, 2022
1 parent 83668de commit 494e514
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 2 deletions.
3 changes: 3 additions & 0 deletions doc/whatsnew/fragments/7938.bugfix
@@ -0,0 +1,3 @@
Fixes a ``ModuleNotFound`` exception when running pylint on a Django project with the ``pylint_django`` plugin enabled.

Closes #7938
4 changes: 2 additions & 2 deletions pylint/lint/pylinter.py
Expand Up @@ -690,8 +690,8 @@ def check(self, files_or_modules: Sequence[str] | str) -> None:
data = None

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

Expand Down

0 comments on commit 494e514

Please sign in to comment.