Skip to content

Commit 32b7046

Browse files
Add clean_lru_cache following review (and remove a circular import)
1 parent e2b912b commit 32b7046

File tree

3 files changed

+39
-18
lines changed

3 files changed

+39
-18
lines changed

pylint/checkers/clear_lru_cache.py

+37
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
# Licensed under the GPL: https://www.gnu.org/licenses/old-licenses/gpl-2.0.html
2+
# For details: https://github.com/pylint-dev/pylint/blob/main/LICENSE
3+
# Copyright (c) https://github.com/pylint-dev/pylint/blob/main/CONTRIBUTORS.txt
4+
5+
from __future__ import annotations
6+
7+
from typing import TYPE_CHECKING, Any
8+
9+
from pylint.checkers.typecheck import _similar_names
10+
from pylint.checkers.utils import (
11+
class_is_abstract,
12+
in_for_else_branch,
13+
infer_all,
14+
is_overload_stub,
15+
overridden_method,
16+
safe_infer,
17+
unimplemented_abstract_methods,
18+
)
19+
20+
if TYPE_CHECKING:
21+
from functools import _lru_cache_wrapper
22+
23+
24+
def clear_lru_caches() -> None:
25+
"""Clear caches holding references to AST nodes."""
26+
caches_holding_node_references: list[_lru_cache_wrapper[Any]] = [
27+
class_is_abstract,
28+
in_for_else_branch,
29+
infer_all,
30+
is_overload_stub,
31+
overridden_method,
32+
unimplemented_abstract_methods,
33+
safe_infer,
34+
_similar_names,
35+
]
36+
for lru in caches_holding_node_references:
37+
lru.cache_clear()

pylint/checkers/utils.py

+1-17
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
from collections.abc import Callable, Iterable, Iterator
1717
from functools import lru_cache, partial
1818
from re import Match
19-
from typing import TYPE_CHECKING, Any, TypeVar
19+
from typing import TYPE_CHECKING, TypeVar
2020

2121
import astroid.objects
2222
from astroid import TooManyLevelsError, nodes, util
@@ -28,7 +28,6 @@
2828
from pylint.constants import TYPING_NEVER, TYPING_NORETURN
2929

3030
if TYPE_CHECKING:
31-
from functools import _lru_cache_wrapper
3231

3332
from pylint.checkers import BaseChecker
3433

@@ -2327,21 +2326,6 @@ def overridden_method(
23272326
return None # pragma: no cover
23282327

23292328

2330-
def clear_lru_caches() -> None:
2331-
"""Clear caches holding references to AST nodes."""
2332-
caches_holding_node_references: list[_lru_cache_wrapper[Any]] = [
2333-
class_is_abstract,
2334-
in_for_else_branch,
2335-
infer_all,
2336-
is_overload_stub,
2337-
overridden_method,
2338-
unimplemented_abstract_methods,
2339-
safe_infer,
2340-
]
2341-
for lru in caches_holding_node_references:
2342-
lru.cache_clear()
2343-
2344-
23452329
def is_enum_member(node: nodes.AssignName) -> bool:
23462330
"""Return `True` if `node` is an Enum member (is an item of the
23472331
`__members__` container).

pylint/lint/run.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
from typing import ClassVar
1313

1414
from pylint import config
15-
from pylint.checkers.utils import clear_lru_caches
15+
from pylint.checkers.clear_lru_cache import clear_lru_caches
1616
from pylint.config._pylint_config import (
1717
_handle_pylint_config_commands,
1818
_register_generate_config_options,

0 commit comments

Comments
 (0)