File tree Expand file tree Collapse file tree 3 files changed +26
-1
lines changed Expand file tree Collapse file tree 3 files changed +26
-1
lines changed 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 16
16
from collections .abc import Iterable , Iterator
17
17
from functools import lru_cache , partial
18
18
from re import Match
19
- from typing import TYPE_CHECKING , Callable , TypeVar
19
+ from typing import TYPE_CHECKING , Any , Callable , TypeVar
20
20
21
21
import _string
22
22
import astroid .objects
27
27
from astroid .typing import InferenceResult , SuccessfulInferenceResult
28
28
29
29
if TYPE_CHECKING :
30
+ from functools import _lru_cache_wrapper
31
+
30
32
from pylint .checkers import BaseChecker
31
33
32
34
_NodeT = TypeVar ("_NodeT" , bound = nodes .NodeNG )
@@ -2243,3 +2245,20 @@ def not_condition_as_string(
2243
2245
)
2244
2246
msg = f"{ lhs } { get_inverse_comparator (ops )} { rhs } "
2245
2247
return msg
2248
+
2249
+
2250
+ def clear_lru_caches () -> None :
2251
+ """Clear caches holding references to AST nodes."""
2252
+ # pylint: disable-next=import-outside-toplevel
2253
+ from pylint .checkers .variables import overridden_method
2254
+
2255
+ caches_holding_node_references : list [_lru_cache_wrapper [Any ]] = [
2256
+ in_for_else_branch ,
2257
+ infer_all ,
2258
+ is_overload_stub ,
2259
+ overridden_method ,
2260
+ unimplemented_abstract_methods ,
2261
+ safe_infer ,
2262
+ ]
2263
+ for lru in caches_holding_node_references :
2264
+ lru .cache_clear ()
Original file line number Diff line number Diff line change 12
12
from typing import Any , ClassVar
13
13
14
14
from pylint import config
15
+ from pylint .checkers .utils import clear_lru_caches
15
16
from pylint .config ._pylint_config import (
16
17
_handle_pylint_config_commands ,
17
18
_register_generate_config_options ,
@@ -222,6 +223,7 @@ def __init__(
222
223
exit = do_exit
223
224
224
225
if linter .config .clear_cache_post_run :
226
+ clear_lru_caches ()
225
227
MANAGER .clear_cache ()
226
228
227
229
if exit :
You can’t perform that action at this time.
0 commit comments