From 494e5145ddf6ffb2d2f16f53b8ad6a2c08e08150 Mon Sep 17 00:00:00 2001 From: "github-actions[bot]" <41898282+github-actions[bot]@users.noreply.github.com> Date: Wed, 14 Dec 2022 20:33:31 +0100 Subject: [PATCH] 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 491eef5b97c4cab5c96f54bc1a8c9cfa1e7b0a51) Co-authored-by: Daniel Harding --- doc/whatsnew/fragments/7938.bugfix | 3 +++ pylint/lint/pylinter.py | 4 ++-- 2 files changed, 5 insertions(+), 2 deletions(-) create mode 100644 doc/whatsnew/fragments/7938.bugfix diff --git a/doc/whatsnew/fragments/7938.bugfix b/doc/whatsnew/fragments/7938.bugfix new file mode 100644 index 0000000000..1cffb9d1f4 --- /dev/null +++ b/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 diff --git a/pylint/lint/pylinter.py b/pylint/lint/pylinter.py index 5a600eb5ba..e8923ad27f 100644 --- a/pylint/lint/pylinter.py +++ b/pylint/lint/pylinter.py @@ -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)