Skip to content

Commit c7b2be1

Browse files
Remove cached decorator
Use `@cached_property` from the stdlib
1 parent 52b2a13 commit c7b2be1

File tree

5 files changed

+5
-46
lines changed

5 files changed

+5
-46
lines changed

ChangeLog

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,9 @@ What's New in astroid 2.16.0?
66
=============================
77
Release date: TBA
88

9+
* Remove ``@cached`` decorator (just use ``@cached_property`` from the stdlib).
10+
11+
Closes #1780
912

1013

1114
What's New in astroid 2.15.2?

astroid/_cache.py

Lines changed: 0 additions & 26 deletions
This file was deleted.

astroid/bases.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
from collections.abc import Sequence
1414
from typing import TYPE_CHECKING, Any, ClassVar
1515

16-
from astroid import decorators, nodes
16+
from astroid import nodes
1717
from astroid.const import PY310_PLUS
1818
from astroid.context import (
1919
CallContext,
@@ -634,7 +634,6 @@ def __init__(
634634
self.parent = parent
635635
self._call_context = copy_context(generator_initial_context)
636636

637-
@decorators.cached
638637
def infer_yield_types(self):
639638
yield from self.parent.infer_yield_result(self._call_context)
640639

astroid/decorators.py

Lines changed: 1 addition & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515

1616
import wrapt
1717

18-
from astroid import _cache, util
18+
from astroid import util
1919
from astroid.context import InferenceContext
2020
from astroid.exceptions import InferenceError
2121

@@ -28,20 +28,6 @@
2828
_P = ParamSpec("_P")
2929

3030

31-
@wrapt.decorator
32-
def cached(func, instance, args, kwargs):
33-
"""Simple decorator to cache result of method calls without args."""
34-
cache = getattr(instance, "__cache", None)
35-
if cache is None:
36-
instance.__cache = cache = {}
37-
_cache.CACHE_MANAGER.add_dict_cache(cache)
38-
try:
39-
return cache[func]
40-
except KeyError:
41-
cache[func] = result = func(*args, **kwargs)
42-
return result
43-
44-
4531
# TODO: Remove when support for 3.7 is dropped
4632
# TODO: astroid 3.0 -> move class behind sys.version_info < (3, 8) guard
4733
class cachedproperty:

astroid/manager.py

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@
1818
from typing import Any, ClassVar
1919

2020
from astroid import nodes
21-
from astroid._cache import CACHE_MANAGER
2221
from astroid.const import BRAIN_MODULES_DIRECTORY
2322
from astroid.context import InferenceContext, _invalidate_cache
2423
from astroid.exceptions import AstroidBuildingError, AstroidImportError
@@ -424,8 +423,6 @@ def clear_cache(self) -> None:
424423
# NB: not a new TransformVisitor()
425424
AstroidManager.brain["_transform"].transforms = collections.defaultdict(list)
426425

427-
CACHE_MANAGER.clear_all_caches()
428-
429426
for lru_cache in (
430427
LookupMixIn.lookup,
431428
_cache_normalize_path_,

0 commit comments

Comments
 (0)