Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Clear context cache in AstroidManager.clear_cache() #2043

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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