summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTakeshi KOMIYA <i.tkomiya@gmail.com>2020-08-13 23:16:59 +0900
committerTakeshi KOMIYA <i.tkomiya@gmail.com>2020-08-13 23:16:59 +0900
commit088b04917033f142b9e9830a2dca86f8d3bc95f1 (patch)
tree9108ab42a516e170e63a0cc910c849665c215270
parent4baa7ce99b6a4a79c203140555743eaa50aed28c (diff)
downloadsphinx-git-088b04917033f142b9e9830a2dca86f8d3bc95f1.tar.gz
Fix #8103: autodoc: cached_property is not considered as a property
sphinx.util.inspect:isproperty() does not considers that cached_property decorator that has been added since Python 3.8 is a kind of properties. This fixes it.
-rw-r--r--CHANGES1
-rw-r--r--sphinx/util/inspect.py5
-rw-r--r--tests/roots/test-ext-autodoc/target/cached_property.py7
-rw-r--r--tests/test_ext_autodoc.py20
4 files changed, 33 insertions, 0 deletions
diff --git a/CHANGES b/CHANGES
index b0b8de1ea..e78905ee6 100644
--- a/CHANGES
+++ b/CHANGES
@@ -16,6 +16,7 @@ Features added
Bugs fixed
----------
+* #8103: autodoc: functools.cached_property is not considered as a property
* #8093: The highlight warning has wrong location in some builders (LaTeX,
singlehtml and so on)
diff --git a/sphinx/util/inspect.py b/sphinx/util/inspect.py
index a5c64f882..37997e6b2 100644
--- a/sphinx/util/inspect.py
+++ b/sphinx/util/inspect.py
@@ -304,6 +304,11 @@ def iscoroutinefunction(obj: Any) -> bool:
def isproperty(obj: Any) -> bool:
"""Check if the object is property."""
+ if sys.version_info > (3, 8):
+ from functools import cached_property # cached_property is available since py3.8
+ if isinstance(obj, cached_property):
+ return True
+
return isinstance(obj, property)
diff --git a/tests/roots/test-ext-autodoc/target/cached_property.py b/tests/roots/test-ext-autodoc/target/cached_property.py
new file mode 100644
index 000000000..63ec09f8e
--- /dev/null
+++ b/tests/roots/test-ext-autodoc/target/cached_property.py
@@ -0,0 +1,7 @@
+from functools import cached_property
+
+
+class Foo:
+ @cached_property
+ def prop(self) -> int:
+ return 1
diff --git a/tests/test_ext_autodoc.py b/tests/test_ext_autodoc.py
index 15e1f3539..b7d3bc54e 100644
--- a/tests/test_ext_autodoc.py
+++ b/tests/test_ext_autodoc.py
@@ -881,6 +881,26 @@ def test_autodoc_descriptor(app):
]
+@pytest.mark.skipif(sys.version_info < (3, 8),
+ reason='cached_property is available since python3.8.')
+@pytest.mark.sphinx('html', testroot='ext-autodoc')
+def test_autodoc_cached_property(app):
+ options = {"members": None,
+ "undoc-members": True}
+ actual = do_autodoc(app, 'class', 'target.cached_property.Foo', options)
+ assert list(actual) == [
+ '',
+ '.. py:class:: Foo()',
+ ' :module: target.cached_property',
+ '',
+ '',
+ ' .. py:method:: Foo.prop',
+ ' :module: target.cached_property',
+ ' :property:',
+ '',
+ ]
+
+
@pytest.mark.sphinx('html', testroot='ext-autodoc')
def test_autodoc_member_order(app):
# case member-order='bysource'