Skip to content

Commit 1aade0f

Browse files
committed
functools.cached_property is considered a property
Closes #436
1 parent fbacc72 commit 1aade0f

File tree

4 files changed

+14
-0
lines changed

4 files changed

+14
-0
lines changed

autoapi/_astroid_utils.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -233,6 +233,9 @@ def _is_property_class(class_node):
233233
return (
234234
class_node.name == "property"
235235
and class_node.root().name == builtins.__name__
236+
) or (
237+
class_node.name == "cached_property"
238+
and class_node.root().name == "functools"
236239
)
237240

238241
for inferred in decorator.infer():

docs/changes/436.feature

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
functools.cached_property is considered a property

tests/python/pyexample/example/example.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
44
This is a description
55
"""
6+
from functools import cached_property
67

78
A_TUPLE = ("a", "b")
89
"""A tuple to be rendered as a tuple."""
@@ -44,6 +45,11 @@ def property_simple(self) -> int:
4445
"""This property should parse okay."""
4546
return 42
4647

48+
@cached_property
49+
def my_cached_property(self) -> int:
50+
"""This cached property should be a property."""
51+
return 42
52+
4753
def method_okay(self, foo=None, bar=None):
4854
"""This method should parse okay"""
4955
return True

tests/python/test_pyintegration.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,10 @@ def check_integration(self, parse, example_path):
9595
== "This property should parse okay."
9696
)
9797

98+
my_cached_property = foo.find(id="example.Foo.my_cached_property")
99+
assert my_cached_property
100+
assert my_cached_property.find(class_="pre").text.strip() == "property"
101+
98102
# Overridden methods without their own docstring
99103
# should inherit the parent's docstring
100104
bar_method_okay = example_file.find(id="example.Bar.method_okay")

0 commit comments

Comments
 (0)