Skip to content

Commit 7fa8481

Browse files
authored
Remove cachedproperty decorator (#2140)
1 parent a91a8d6 commit 7fa8481

File tree

3 files changed

+4
-65
lines changed

3 files changed

+4
-65
lines changed

ChangeLog

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,17 +2,18 @@
22
astroid's ChangeLog
33
===================
44

5-
What's New in astroid 2.16.0?
5+
What's New in astroid 3.0.0?
66
=============================
77
Release date: TBA
88

99
* Remove support for Python 3.7.
1010

1111
Refs #2137
1212

13-
* Remove ``@cached`` decorator (just use ``@cached_property`` from the stdlib).
13+
* Remove ``@cached`` and ``@cachedproperty`` decorator (just use ``@cached_property`` from the stdlib).
1414

1515
Closes #1780
16+
Refs #2140
1617

1718
* Reduce file system access in ``ast_from_file()``.
1819

astroid/decorators.py

Lines changed: 0 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -27,52 +27,6 @@
2727
_P = ParamSpec("_P")
2828

2929

30-
# TODO: Remove for astroid 3.0
31-
class cachedproperty:
32-
"""Provides a cached property equivalent to the stacking of
33-
@cached and @property, but more efficient.
34-
35-
After first usage, the <property_name> becomes part of the object's
36-
__dict__. Doing:
37-
38-
del obj.<property_name> empties the cache.
39-
40-
Idea taken from the pyramid_ framework and the mercurial_ project.
41-
42-
.. _pyramid: http://pypi.python.org/pypi/pyramid
43-
.. _mercurial: http://pypi.python.org/pypi/Mercurial
44-
"""
45-
46-
__slots__ = ("wrapped",)
47-
48-
def __init__(self, wrapped):
49-
warnings.warn(
50-
"cachedproperty has been deprecated and will be removed in astroid 3.0"
51-
"Use functools.cached_property instead.",
52-
DeprecationWarning,
53-
stacklevel=2,
54-
)
55-
try:
56-
wrapped.__name__ # noqa[B018]
57-
except AttributeError as exc:
58-
raise TypeError(f"{wrapped} must have a __name__ attribute") from exc
59-
self.wrapped = wrapped
60-
61-
@property
62-
def __doc__(self):
63-
doc = getattr(self.wrapped, "__doc__", None)
64-
return "<wrapped by the cachedproperty decorator>%s" % (
65-
"\n%s" % doc if doc else ""
66-
)
67-
68-
def __get__(self, inst, objtype=None):
69-
if inst is None:
70-
return self
71-
val = self.wrapped(inst)
72-
setattr(inst, self.wrapped.__name__, val)
73-
return val
74-
75-
7630
def path_wrapper(func):
7731
"""Return the given infer function wrapped to handle the path.
7832

tests/test_decorators.py

Lines changed: 1 addition & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,7 @@
55
import pytest
66
from _pytest.recwarn import WarningsRecorder
77

8-
from astroid.const import PY38_PLUS
9-
from astroid.decorators import cachedproperty, deprecate_default_argument_values
8+
from astroid.decorators import deprecate_default_argument_values
109

1110

1211
class SomeClass:
@@ -102,18 +101,3 @@ def test_deprecated_default_argument_values_ok(recwarn: WarningsRecorder) -> Non
102101
instance = SomeClass(name="some_name")
103102
instance.func(name="", var=42)
104103
assert len(recwarn) == 0
105-
106-
107-
@pytest.mark.skipif(not PY38_PLUS, reason="Requires Python 3.8 or higher")
108-
def test_deprecation_warning_on_cachedproperty() -> None:
109-
"""Check the DeprecationWarning on cachedproperty."""
110-
111-
with pytest.warns(DeprecationWarning) as records:
112-
113-
class MyClass: # pylint: disable=unused-variable
114-
@cachedproperty
115-
def my_property(self):
116-
return 1
117-
118-
assert len(records) == 1
119-
assert "functools.cached_property" in records[0].message.args[0]

0 commit comments

Comments
 (0)