File tree Expand file tree Collapse file tree 2 files changed +29
-1
lines changed Expand file tree Collapse file tree 2 files changed +29
-1
lines changed Original file line number Diff line number Diff line change 1212import sys
1313
1414
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+
1522def strip_blank_lines (l ):
1623 "Remove leading and trailing blank lines from a list of lines"
1724 while l and not l [0 ].strip ():
@@ -706,7 +713,7 @@ def properties(self):
706713 not name .startswith ("_" )
707714 and (
708715 func is None
709- or isinstance (func , property )
716+ or isinstance (func , ( property , cached_property ) )
710717 or inspect .isdatadescriptor (func )
711718 )
712719 and self ._is_show_member (name )
Original file line number Diff line number Diff line change 11from collections import namedtuple
22from copy import deepcopy
33import re
4+ import sys
45import textwrap
56import warnings
67
@@ -1624,6 +1625,26 @@ def __call__(self):
16241625 nds ._error_location (msg = msg )
16251626
16261627
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+
16271648if __name__ == "__main__" :
16281649 import pytest
16291650
You can’t perform that action at this time.
0 commit comments