File tree 3 files changed +26
-1
lines changed
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 17
17
from collections .abc import Iterable , Iterator
18
18
from functools import lru_cache , partial
19
19
from re import Match
20
- from typing import TYPE_CHECKING , Callable , TypeVar
20
+ from typing import TYPE_CHECKING , Any , Callable , TypeVar
21
21
22
22
import _string
23
23
import astroid .objects
28
28
from astroid .typing import InferenceResult , SuccessfulInferenceResult
29
29
30
30
if TYPE_CHECKING :
31
+ from functools import _lru_cache_wrapper
32
+
31
33
from pylint .checkers import BaseChecker
32
34
33
35
_NodeT = TypeVar ("_NodeT" , bound = nodes .NodeNG )
@@ -2295,3 +2297,20 @@ def not_condition_as_string(
2295
2297
)
2296
2298
msg = f"{ lhs } { get_inverse_comparator (ops )} { rhs } "
2297
2299
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 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