diff options
author | Drummond Ogilvie <drum.ogilvie@ovo.com> | 2022-10-20 10:16:34 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-10-20 11:16:34 +0200 |
commit | 015f3403385896f70ba946e10ad8354f1a59a967 (patch) | |
tree | 2c84d9c90f3911fca7da69cb4269a60478cbb2cc /pylint/lint | |
parent | e8ba3eb002b533e6640d6eeb25a66bab04602951 (diff) | |
download | pylint-git-015f3403385896f70ba946e10ad8354f1a59a967.tar.gz |
Swap plugin cache to pickle-able values when done (#7640)
When the dictionary has served its purpose (making plugin loading
pre-and-post init a consistent behaviour), we swap it for bools
indicating whether or not a module was loaded.
We don't currently use the bools, but it seemed a sensible choice.
The main idea is to make the dictionary fully pickle-able, so that when
dill pickles the linter for multiprocessing, it doesn't crash horribly.
Co-authored-by: Daniƫl van Noord <13665637+DanielNoord@users.noreply.github.com>
Co-authored-by: Marc Mueller <30130371+cdce8p@users.noreply.github.com>
Diffstat (limited to 'pylint/lint')
-rw-r--r-- | pylint/lint/pylinter.py | 12 |
1 files changed, 10 insertions, 2 deletions
diff --git a/pylint/lint/pylinter.py b/pylint/lint/pylinter.py index 12726e278..d337fd32c 100644 --- a/pylint/lint/pylinter.py +++ b/pylint/lint/pylinter.py @@ -296,7 +296,7 @@ class PyLinter( str, list[checkers.BaseChecker] ] = collections.defaultdict(list) """Dictionary of registered and initialized checkers.""" - self._dynamic_plugins: dict[str, ModuleType | ModuleNotFoundError] = {} + self._dynamic_plugins: dict[str, ModuleType | ModuleNotFoundError | bool] = {} """Set of loaded plugin names.""" # Attributes related to registering messages and their handling @@ -402,7 +402,15 @@ class PyLinter( "bad-plugin-value", args=(modname, module_or_error), line=0 ) elif hasattr(module_or_error, "load_configuration"): - module_or_error.load_configuration(self) + module_or_error.load_configuration(self) # type: ignore[union-attr] + + # We re-set all the dictionary values to True here to make sure the dict + # is pickle-able. This is only a problem in multiprocessing/parallel mode. + # (e.g. invoking pylint -j 2) + self._dynamic_plugins = { + modname: not isinstance(val, ModuleNotFoundError) + for modname, val in self._dynamic_plugins.items() + } def _load_reporters(self, reporter_names: str) -> None: """Load the reporters if they are available on _reporters.""" |