Skip to content

Commit

Permalink
functools.cached_property is considered a property
Browse files Browse the repository at this point in the history
Closes #436
  • Loading branch information
AWhetter committed Jun 22, 2024
1 parent fbacc72 commit 1aade0f
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 0 deletions.
3 changes: 3 additions & 0 deletions autoapi/_astroid_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -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():
Expand Down
1 change: 1 addition & 0 deletions docs/changes/436.feature
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
functools.cached_property is considered a property
6 changes: 6 additions & 0 deletions tests/python/pyexample/example/example.py
Original file line number Diff line number Diff line change
Expand Up @@ -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."""
Expand Down Expand Up @@ -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
Expand Down
4 changes: 4 additions & 0 deletions tests/python/test_pyintegration.py
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down

0 comments on commit 1aade0f

Please sign in to comment.