File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 1+ ``--clear-cache-post-run`` now also clears LRU caches for pylint utilities
2+ holding references to AST nodes.
3+
4+ Closes #8361
Original file line number Diff line number Diff line change 1717from collections .abc import Iterable , Iterator
1818from functools import lru_cache , partial
1919from re import Match
20- from typing import TYPE_CHECKING , Callable , TypeVar
20+ from typing import TYPE_CHECKING , Any , Callable , TypeVar
2121
2222import _string
2323import astroid .objects
2828from astroid .typing import InferenceResult , SuccessfulInferenceResult
2929
3030if TYPE_CHECKING :
31+ from functools import _lru_cache_wrapper
32+
3133 from pylint .checkers import BaseChecker
3234
3335_NodeT = TypeVar ("_NodeT" , bound = nodes .NodeNG )
@@ -2295,3 +2297,20 @@ def not_condition_as_string(
22952297 )
22962298 msg = f"{ lhs } { get_inverse_comparator (ops )} { rhs } "
22972299 return msg
2300+
2301+
2302+ def clear_lru_caches () -> None :
2303+ """Clear caches holding references to AST nodes."""
2304+ # pylint: disable-next=import-outside-toplevel
2305+ from pylint .checkers .variables import overridden_method
2306+
2307+ caches_holding_node_references : list [_lru_cache_wrapper [Any ]] = [
2308+ in_for_else_branch ,
2309+ infer_all ,
2310+ is_overload_stub ,
2311+ overridden_method ,
2312+ unimplemented_abstract_methods ,
2313+ safe_infer ,
2314+ ]
2315+ for lru in caches_holding_node_references :
2316+ lru .cache_clear ()
Original file line number Diff line number Diff line change 1212from typing import Any , ClassVar
1313
1414from pylint import config
15+ from pylint .checkers .utils import clear_lru_caches
1516from pylint .config ._pylint_config import (
1617 _handle_pylint_config_commands ,
1718 _register_generate_config_options ,
@@ -222,6 +223,7 @@ def __init__(
222223 exit = do_exit
223224
224225 if linter .config .clear_cache_post_run :
226+ clear_lru_caches ()
225227 MANAGER .clear_cache ()
226228
227229 if exit :
You can’t perform that action at this time.
0 commit comments