clear_lru_cache.py 1.0 KB

12345678910111213141516171819202122232425262728293031323334353637
  1. # Licensed under the GPL: https://www.gnu.org/licenses/old-licenses/gpl-2.0.html
  2. # For details: https://github.com/pylint-dev/pylint/blob/main/LICENSE
  3. # Copyright (c) https://github.com/pylint-dev/pylint/blob/main/CONTRIBUTORS.txt
  4. from __future__ import annotations
  5. from typing import TYPE_CHECKING, Any
  6. from pylint.checkers.typecheck import _similar_names
  7. from pylint.checkers.utils import (
  8. class_is_abstract,
  9. in_for_else_branch,
  10. infer_all,
  11. is_overload_stub,
  12. overridden_method,
  13. safe_infer,
  14. unimplemented_abstract_methods,
  15. )
  16. if TYPE_CHECKING:
  17. from functools import _lru_cache_wrapper
  18. def clear_lru_caches() -> None:
  19. """Clear caches holding references to AST nodes."""
  20. caches_holding_node_references: list[_lru_cache_wrapper[Any]] = [
  21. class_is_abstract,
  22. in_for_else_branch,
  23. infer_all,
  24. is_overload_stub,
  25. overridden_method,
  26. unimplemented_abstract_methods,
  27. safe_infer,
  28. _similar_names,
  29. ]
  30. for lru in caches_holding_node_references:
  31. lru.cache_clear()