Skip to content

Commit 75423e7

Browse files
Clear context cache in AstroidManager.clear_cache()
1 parent 925910a commit 75423e7

File tree

3 files changed

+9
-2
lines changed

3 files changed

+9
-2
lines changed

ChangeLog

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,10 @@ Release date: TBA
1919

2020
Refs PyCQA/pylint#5288
2121

22+
* ``AstroidManager.clear_cache`` now also clears the inference context cache.
23+
24+
Refs #1780
25+
2226
* ``Astroid`` now retrieves the default values of keyword only arguments and sets them on
2327
``Arguments.kw_defaults``.
2428

astroid/manager.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
from astroid import nodes
2121
from astroid._cache import CACHE_MANAGER
2222
from astroid.const import BRAIN_MODULES_DIRECTORY
23-
from astroid.context import InferenceContext
23+
from astroid.context import InferenceContext, _invalidate_cache
2424
from astroid.exceptions import AstroidBuildingError, AstroidImportError
2525
from astroid.interpreter._import import spec, util
2626
from astroid.modutils import (
@@ -407,7 +407,7 @@ def bootstrap(self) -> None:
407407
raw_building._astroid_bootstrapping()
408408

409409
def clear_cache(self) -> None:
410-
"""Clear the underlying cache, bootstrap the builtins module and
410+
"""Clear the underlying caches, bootstrap the builtins module and
411411
re-register transforms.
412412
"""
413413
# import here because of cyclic imports
@@ -418,6 +418,7 @@ def clear_cache(self) -> None:
418418
from astroid.nodes.scoped_nodes import ClassDef
419419

420420
clear_inference_tip_cache()
421+
_invalidate_cache() # inference context cache
421422

422423
self.astroid_cache.clear()
423424
# NB: not a new TransformVisitor()

tests/test_manager.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -430,6 +430,8 @@ def test_clear_cache_clears_other_lru_caches(self) -> None:
430430

431431
astroid.MANAGER.clear_cache() # also calls bootstrap()
432432

433+
self.assertEqual(astroid.context._INFERENCE_CACHE, {})
434+
433435
# The cache sizes are now as low or lower than the original baseline
434436
cleared_cache_infos = [lru.cache_info() for lru in lrus]
435437
for cleared_cache, baseline_cache in zip(

0 commit comments

Comments
 (0)