Skip to content

Commit

Permalink
Clear context cache in AstroidManager.clear_cache()
Browse files Browse the repository at this point in the history
  • Loading branch information
jacobtylerwalls committed Mar 4, 2023
1 parent 925910a commit 75423e7
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 2 deletions.
4 changes: 4 additions & 0 deletions ChangeLog
Original file line number Diff line number Diff line change
Expand Up @@ -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``.

Expand Down
5 changes: 3 additions & 2 deletions astroid/manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 (
Expand Down Expand Up @@ -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
Expand All @@ -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()
Expand Down
2 changes: 2 additions & 0 deletions tests/test_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down

0 comments on commit 75423e7

Please sign in to comment.