Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add ignored modules to Astroid module deny list #9504

Merged
merged 4 commits into from
May 12, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion doc/user_guide/configuration/all-options.rst
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ Standard Checkers

--ignored-modules
"""""""""""""""""
*List of module names for which member attributes should not be checked (useful for modules/projects where namespaces are manipulated during runtime and thus existing member attributes cannot be deduced by static analysis). It supports qualified module names, as well as Unix pattern matching.*
*List of module names for which member attributes should not be checked and will not be imported (useful for modules/projects where namespaces are manipulated during runtime and thus existing member attributes cannot be deduced by static analysis). It supports qualified module names, as well as Unix pattern matching.*

**Default:** ``()``

Expand Down
5 changes: 5 additions & 0 deletions doc/whatsnew/fragments/9442.other
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
Ignored modules are now not checked at all, instead of being checked and then
ignored. This should speed up the analysis of large codebases which have
ignored modules.

Closes #9442 (`#9442 <https://github.com/pylint-dev/pylint/issues/9442>`_)
1 change: 1 addition & 0 deletions pylint/lint/pylinter.py
Original file line number Diff line number Diff line change
Expand Up @@ -1073,6 +1073,7 @@ def open(self) -> None:
MANAGER.always_load_extensions = self.config.unsafe_load_any_extension
MANAGER.max_inferable_values = self.config.limit_inference_results
MANAGER.extension_package_whitelist.update(self.config.extension_pkg_allow_list)
MANAGER.module_denylist.update(self.config.ignored_modules)
if self.config.extension_pkg_whitelist:
MANAGER.extension_package_whitelist.update(
self.config.extension_pkg_whitelist
Expand Down
13 changes: 12 additions & 1 deletion tests/lint/test_pylinter.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@

from pytest import CaptureFixture

from pylint.lint.pylinter import PyLinter
from pylint.lint.pylinter import MANAGER, PyLinter
from pylint.utils import FileState


Expand Down Expand Up @@ -48,3 +48,14 @@ def test_crash_during_linting(
assert len(files) == 1
assert "pylint-crash-20" in str(files[0])
assert any(m.symbol == "astroid-error" for m in linter.reporter.messages)


def test_open_pylinter_denied_modules(linter: PyLinter) -> None:
"""Test PyLinter open() adds ignored modules to Astroid manager deny list."""
MANAGER.module_denylist = {"mod1"}
try:
linter.config.ignored_modules = ["mod2", "mod3"]
linter.open()
assert MANAGER.module_denylist == {"mod1", "mod2", "mod3"}
finally:
MANAGER.module_denylist = set()