summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJacob Walls <jacobtylerwalls@gmail.com>2023-03-04 14:31:03 -0500
committerJacob Walls <jacobtylerwalls@gmail.com>2023-03-04 14:56:57 -0500
commit7aa2c3413086585558a8b75fb38f04d2c4054a25 (patch)
tree3c0b191d0ad02fc94918aae45c866aa8bb990d09
parent925910a8f2c9005a02597cfa2b830bf5a5eef9d8 (diff)
downloadastroid-git-7aa2c3413086585558a8b75fb38f04d2c4054a25.tar.gz
Clear context cache in AstroidManager.clear_cache()
-rw-r--r--ChangeLog4
-rw-r--r--astroid/manager.py5
-rw-r--r--tests/test_manager.py2
3 files changed, 9 insertions, 2 deletions
diff --git a/ChangeLog b/ChangeLog
index 1fae3079..a0d3fb6a 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -19,6 +19,10 @@ Release date: TBA
Refs PyCQA/pylint#5288
+* ``AstroidManager.clear_cache`` now also clears the inference context cache.
+
+ Refs #1780
+
* ``Astroid`` now retrieves the default values of keyword only arguments and sets them on
``Arguments.kw_defaults``.
diff --git a/astroid/manager.py b/astroid/manager.py
index b0cecc30..965dd5a5 100644
--- a/astroid/manager.py
+++ b/astroid/manager.py
@@ -20,7 +20,7 @@ from typing import Any, ClassVar
from astroid import nodes
from astroid._cache import CACHE_MANAGER
from astroid.const import BRAIN_MODULES_DIRECTORY
-from astroid.context import InferenceContext
+from astroid.context import InferenceContext, _invalidate_cache
from astroid.exceptions import AstroidBuildingError, AstroidImportError
from astroid.interpreter._import import spec, util
from astroid.modutils import (
@@ -407,7 +407,7 @@ class AstroidManager:
raw_building._astroid_bootstrapping()
def clear_cache(self) -> None:
- """Clear the underlying cache, bootstrap the builtins module and
+ """Clear the underlying caches, bootstrap the builtins module and
re-register transforms.
"""
# import here because of cyclic imports
@@ -418,6 +418,7 @@ class AstroidManager:
from astroid.nodes.scoped_nodes import ClassDef
clear_inference_tip_cache()
+ _invalidate_cache() # inference context cache
self.astroid_cache.clear()
# NB: not a new TransformVisitor()
diff --git a/tests/test_manager.py b/tests/test_manager.py
index f90be5c8..9b9b24fe 100644
--- a/tests/test_manager.py
+++ b/tests/test_manager.py
@@ -430,6 +430,8 @@ class ClearCacheTest(unittest.TestCase):
astroid.MANAGER.clear_cache() # also calls bootstrap()
+ self.assertEqual(astroid.context._INFERENCE_CACHE, {})
+
# The cache sizes are now as low or lower than the original baseline
cleared_cache_infos = [lru.cache_info() for lru in lrus]
for cleared_cache, baseline_cache in zip(