diff --git a/ChangeLog b/ChangeLog index 1fae3079b..a0d3fb6a2 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 b0cecc30c..965dd5a57 100644 --- a/astroid/manager.py +++ b/astroid/manager.py @@ -20,7 +20,7 @@ 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 @@ def bootstrap(self) -> None: 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 @@ def clear_cache(self) -> None: 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 f90be5c81..9b9b24fe5 100644 --- a/tests/test_manager.py +++ b/tests/test_manager.py @@ -430,6 +430,8 @@ def test_clear_cache_clears_other_lru_caches(self) -> None: 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(