File tree Expand file tree Collapse file tree 5 files changed +133
-2
lines changed
flake8_docstrings_complete Expand file tree Collapse file tree 5 files changed +133
-2
lines changed Original file line number Diff line number Diff line change 2
2
3
3
## [ Unreleased]
4
4
5
+ ## [ v1.2.0] - 2023-07-12
6
+
7
+ ### Added
8
+
9
+ - Support for ` functools.cached_property ` .
10
+
5
11
## [ v1.1.0] - 2023-01-26
6
12
7
13
### Added
Original file line number Diff line number Diff line change @@ -1420,6 +1420,16 @@ class FooClass:
1420
1420
def bar (self ):
1421
1421
return " bar"
1422
1422
1423
+ class FooClass :
1424
+ """ Perform foo action.
1425
+
1426
+ Attrs:
1427
+ """
1428
+
1429
+ @functools.cached_property
1430
+ def bar (self ):
1431
+ return " bar"
1432
+
1423
1433
class FooClass :
1424
1434
""" Perform foo action.
1425
1435
@@ -1461,6 +1471,17 @@ class FooClass:
1461
1471
def bar (self ):
1462
1472
return " bar"
1463
1473
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
+
1464
1485
class FooClass :
1465
1486
""" Perform foo action.
1466
1487
Original file line number Diff line number Diff line change @@ -55,13 +55,23 @@ def is_property_decorator(node: ast.expr) -> bool:
55
55
Whether the node is a property decorator.
56
56
"""
57
57
if isinstance (node , ast .Name ):
58
- return node .id == "property"
58
+ return node .id in { "property" , "cached_property" }
59
59
60
60
# Handle call
61
61
if isinstance (node , ast .Call ):
62
62
return is_property_decorator (node = node .func )
63
63
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
65
75
66
76
67
77
def _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):
569
569
class Class1:
570
570
"""Docstring.
571
571
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
+
572
604
Attrs:
573
605
function_1:
574
606
"""
Original file line number Diff line number Diff line change @@ -183,6 +183,36 @@ def attr_1():
183
183
class Class1:
184
184
"""Docstring 1.
185
185
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
+
186
216
Attrs:
187
217
"""
188
218
@property
@@ -583,6 +613,38 @@ def attr_1():
583
613
class Class1:
584
614
"""Docstring 1.
585
615
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
+
586
648
Attrs:
587
649
attr_1:
588
650
"""
You can’t perform that action at this time.
0 commit comments