diff --git a/autoapi/_astroid_utils.py b/autoapi/_astroid_utils.py index 77d7105f..33c11fd7 100644 --- a/autoapi/_astroid_utils.py +++ b/autoapi/_astroid_utils.py @@ -233,6 +233,9 @@ def _is_property_class(class_node): return ( class_node.name == "property" and class_node.root().name == builtins.__name__ + ) or ( + class_node.name == "cached_property" + and class_node.root().name == "functools" ) for inferred in decorator.infer(): diff --git a/docs/changes/436.feature b/docs/changes/436.feature new file mode 100644 index 00000000..05571ec0 --- /dev/null +++ b/docs/changes/436.feature @@ -0,0 +1 @@ +functools.cached_property is considered a property \ No newline at end of file diff --git a/tests/python/pyexample/example/example.py b/tests/python/pyexample/example/example.py index 2572731d..0df390fe 100644 --- a/tests/python/pyexample/example/example.py +++ b/tests/python/pyexample/example/example.py @@ -3,6 +3,7 @@ This is a description """ +from functools import cached_property A_TUPLE = ("a", "b") """A tuple to be rendered as a tuple.""" @@ -44,6 +45,11 @@ def property_simple(self) -> int: """This property should parse okay.""" return 42 + @cached_property + def my_cached_property(self) -> int: + """This cached property should be a property.""" + return 42 + def method_okay(self, foo=None, bar=None): """This method should parse okay""" return True diff --git a/tests/python/test_pyintegration.py b/tests/python/test_pyintegration.py index 5f8657b6..a4ba69f3 100644 --- a/tests/python/test_pyintegration.py +++ b/tests/python/test_pyintegration.py @@ -95,6 +95,10 @@ def check_integration(self, parse, example_path): == "This property should parse okay." ) + my_cached_property = foo.find(id="example.Foo.my_cached_property") + assert my_cached_property + assert my_cached_property.find(class_="pre").text.strip() == "property" + # Overridden methods without their own docstring # should inherit the parent's docstring bar_method_okay = example_file.find(id="example.Bar.method_okay")