File tree 2 files changed +29
-1
lines changed
2 files changed +29
-1
lines changed Original file line number Diff line number Diff line change 12
12
import sys
13
13
14
14
15
+ # TODO: Remove try-except when support for Python 3.7 is dropped
16
+ try :
17
+ from functools import cached_property
18
+ except ImportError : # cached_property added in Python 3.8
19
+ cached_property = property
20
+
21
+
15
22
def strip_blank_lines (l ):
16
23
"Remove leading and trailing blank lines from a list of lines"
17
24
while l and not l [0 ].strip ():
@@ -706,7 +713,7 @@ def properties(self):
706
713
not name .startswith ("_" )
707
714
and (
708
715
func is None
709
- or isinstance (func , property )
716
+ or isinstance (func , ( property , cached_property ) )
710
717
or inspect .isdatadescriptor (func )
711
718
)
712
719
and self ._is_show_member (name )
Original file line number Diff line number Diff line change 1
1
from collections import namedtuple
2
2
from copy import deepcopy
3
3
import re
4
+ import sys
4
5
import textwrap
5
6
import warnings
6
7
@@ -1624,6 +1625,26 @@ def __call__(self):
1624
1625
nds ._error_location (msg = msg )
1625
1626
1626
1627
1628
+ @pytest .mark .skipif (
1629
+ sys .version_info < (3 , 8 ), reason = "cached_property was added in 3.8"
1630
+ )
1631
+ def test_class_docstring_cached_property ():
1632
+ """Ensure that properties marked with the `cached_property` decorator
1633
+ are listed in the Methods section. See gh-432."""
1634
+ from functools import cached_property
1635
+
1636
+ class Foo :
1637
+ _x = [1 , 2 , 3 ]
1638
+
1639
+ @cached_property
1640
+ def val (self ):
1641
+ return self ._x
1642
+
1643
+ class_docstring = get_doc_object (Foo )
1644
+ assert len (class_docstring ["Attributes" ]) == 1
1645
+ assert class_docstring ["Attributes" ][0 ].name == "val"
1646
+
1647
+
1627
1648
if __name__ == "__main__" :
1628
1649
import pytest
1629
1650
You can’t perform that action at this time.
0 commit comments