diff options
author | Jacob Walls <jacobtylerwalls@gmail.com> | 2023-03-10 15:00:42 -0500 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-03-10 15:00:42 -0500 |
commit | ab20812ad0e9ca17cc3bc32dbf34be575dcea502 (patch) | |
tree | 27be7b6fcb9d1235a0233296ea4797ec23b5d333 /pylint | |
parent | 958ff856a25c1b6152c6f0a03d7488a6278adebf (diff) | |
download | pylint-git-ab20812ad0e9ca17cc3bc32dbf34be575dcea502.tar.gz |
Clear LRU caches on pylint utilities (#8420)
Diffstat (limited to 'pylint')
-rw-r--r-- | pylint/checkers/utils.py | 21 | ||||
-rw-r--r-- | pylint/lint/run.py | 2 |
2 files changed, 22 insertions, 1 deletions
diff --git a/pylint/checkers/utils.py b/pylint/checkers/utils.py index d1d77dc0a..4fdb3ad22 100644 --- a/pylint/checkers/utils.py +++ b/pylint/checkers/utils.py @@ -16,7 +16,7 @@ from collections import deque from collections.abc import Iterable, Iterator from functools import lru_cache, partial from re import Match -from typing import TYPE_CHECKING, Callable, TypeVar +from typing import TYPE_CHECKING, Any, Callable, TypeVar import _string import astroid.objects @@ -27,6 +27,8 @@ from astroid.nodes._base_nodes import ImportNode from astroid.typing import InferenceResult, SuccessfulInferenceResult if TYPE_CHECKING: + from functools import _lru_cache_wrapper + from pylint.checkers import BaseChecker _NodeT = TypeVar("_NodeT", bound=nodes.NodeNG) @@ -2243,3 +2245,20 @@ def not_condition_as_string( ) msg = f"{lhs} {get_inverse_comparator(ops)} {rhs}" return msg + + +def clear_lru_caches() -> None: + """Clear caches holding references to AST nodes.""" + # pylint: disable-next=import-outside-toplevel + from pylint.checkers.variables import overridden_method + + caches_holding_node_references: list[_lru_cache_wrapper[Any]] = [ + in_for_else_branch, + infer_all, + is_overload_stub, + overridden_method, + unimplemented_abstract_methods, + safe_infer, + ] + for lru in caches_holding_node_references: + lru.cache_clear() diff --git a/pylint/lint/run.py b/pylint/lint/run.py index 2232c41a3..49b807f87 100644 --- a/pylint/lint/run.py +++ b/pylint/lint/run.py @@ -12,6 +12,7 @@ from pathlib import Path from typing import Any, ClassVar from pylint import config +from pylint.checkers.utils import clear_lru_caches from pylint.config._pylint_config import ( _handle_pylint_config_commands, _register_generate_config_options, @@ -222,6 +223,7 @@ group are mutually exclusive.", exit = do_exit if linter.config.clear_cache_post_run: + clear_lru_caches() MANAGER.clear_cache() if exit: |