File tree Expand file tree Collapse file tree
flake8_docstrings_complete Expand file tree Collapse file tree Original file line number Diff line number Diff line change 22
33## [ Unreleased]
44
5+ ## [ v1.2.0] - 2023-07-12
6+
7+ ### Added
8+
9+ - Support for ` functools.cached_property ` .
10+
511## [ v1.1.0] - 2023-01-26
612
713### Added
Original file line number Diff line number Diff line change @@ -1420,6 +1420,16 @@ class FooClass:
14201420 def bar (self ):
14211421 return " bar"
14221422
1423+ class FooClass :
1424+ """ Perform foo action.
1425+
1426+ Attrs:
1427+ """
1428+
1429+ @functools.cached_property
1430+ def bar (self ):
1431+ return " bar"
1432+
14231433class FooClass :
14241434 """ Perform foo action.
14251435
@@ -1461,6 +1471,17 @@ class FooClass:
14611471 def bar (self ):
14621472 return " bar"
14631473
1474+ class FooClass :
1475+ """ Perform foo action.
1476+
1477+ Attrs:
1478+ bar: The value to perform the foo action on.
1479+ """
1480+
1481+ @functools.cached_property
1482+ def bar (self ):
1483+ return " bar"
1484+
14641485class FooClass :
14651486 """ Perform foo action.
14661487
Original file line number Diff line number Diff line change @@ -55,13 +55,23 @@ def is_property_decorator(node: ast.expr) -> bool:
5555 Whether the node is a property decorator.
5656 """
5757 if isinstance (node , ast .Name ):
58- return node .id == "property"
58+ return node .id in { "property" , "cached_property" }
5959
6060 # Handle call
6161 if isinstance (node , ast .Call ):
6262 return is_property_decorator (node = node .func )
6363
64- return False
64+ # Handle attr
65+ if isinstance (node , ast .Attribute ):
66+ value = node .value
67+ return (
68+ node .attr == "cached_property"
69+ and isinstance (value , ast .Name )
70+ and value .id == "functools"
71+ )
72+
73+ # There is no valid syntax that gets to here
74+ return False # pragma: nocover
6575
6676
6777def _get_class_target_name (target : ast .expr ) -> ast .Name | None :
Original file line number Diff line number Diff line change @@ -569,6 +569,38 @@ def function_1(self):
569569class Class1:
570570 """Docstring.
571571
572+ Attrs:
573+ function_1:
574+ """
575+ @cached_property
576+ def function_1(self):
577+ """Docstring 1."""
578+ return 1
579+ ''' ,
580+ (),
581+ id = "cached_property return value docstring no returns section" ,
582+ ),
583+ pytest .param (
584+ '''
585+ class Class1:
586+ """Docstring.
587+
588+ Attrs:
589+ function_1:
590+ """
591+ @functools.cached_property
592+ def function_1(self):
593+ """Docstring 1."""
594+ return 1
595+ ''' ,
596+ (),
597+ id = "functools.cached_property return value docstring no returns section" ,
598+ ),
599+ pytest .param (
600+ '''
601+ class Class1:
602+ """Docstring.
603+
572604 Attrs:
573605 function_1:
574606 """
Original file line number Diff line number Diff line change @@ -183,6 +183,36 @@ def attr_1():
183183class Class1:
184184 """Docstring 1.
185185
186+ Attrs:
187+ """
188+ @cached_property
189+ def attr_1():
190+ """Docstring 2."""
191+ return "value 1"
192+ ''' ,
193+ (f"8:4 { ATTR_NOT_IN_DOCSTR_MSG % 'attr_1' } " ,),
194+ id = "class has single cached_property docstring no attr" ,
195+ ),
196+ pytest .param (
197+ '''
198+ class Class1:
199+ """Docstring 1.
200+
201+ Attrs:
202+ """
203+ @functools.cached_property
204+ def attr_1():
205+ """Docstring 2."""
206+ return "value 1"
207+ ''' ,
208+ (f"8:4 { ATTR_NOT_IN_DOCSTR_MSG % 'attr_1' } " ,),
209+ id = "class has single functools.cached_property docstring no attr" ,
210+ ),
211+ pytest .param (
212+ '''
213+ class Class1:
214+ """Docstring 1.
215+
186216 Attrs:
187217 """
188218 @property
@@ -583,6 +613,38 @@ def attr_1():
583613class Class1:
584614 """Docstring 1.
585615
616+ Attrs:
617+ attr_1:
618+ """
619+ @cached_property
620+ def attr_1():
621+ """Docstring 2."""
622+ return "value 1"
623+ ''' ,
624+ (),
625+ id = "class single cached_property docstring single attr" ,
626+ ),
627+ pytest .param (
628+ '''
629+ class Class1:
630+ """Docstring 1.
631+
632+ Attrs:
633+ attr_1:
634+ """
635+ @functools.cached_property
636+ def attr_1():
637+ """Docstring 2."""
638+ return "value 1"
639+ ''' ,
640+ (),
641+ id = "class single functools.cached_property docstring single attr" ,
642+ ),
643+ pytest .param (
644+ '''
645+ class Class1:
646+ """Docstring 1.
647+
586648 Attrs:
587649 attr_1:
588650 """
You can’t perform that action at this time.
0 commit comments