mirror of
https://github.com/sphinx-doc/sphinx.git
synced 2025-02-25 18:55:22 -06:00
Merge pull request #8111 from tk0miya/8103_cached_property
Fix #8103: autodoc: cached_property is not considered as a property
This commit is contained in:
commit
000210e7c2
1
CHANGES
1
CHANGES
@ -22,6 +22,7 @@ Bugs fixed
|
||||
* #8085: i18n: Add support for having single text domain
|
||||
* #8143: autodoc: AttributeError is raised when False value is passed to
|
||||
autodoc_default_options
|
||||
* #8103: autodoc: functools.cached_property is not considered as a property
|
||||
* #8192: napoleon: description is disappeared when it contains inline literals
|
||||
* #8093: The highlight warning has wrong location in some builders (LaTeX,
|
||||
singlehtml and so on)
|
||||
|
@ -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)
|
||||
|
||||
|
||||
|
7
tests/roots/test-ext-autodoc/target/cached_property.py
Normal file
7
tests/roots/test-ext-autodoc/target/cached_property.py
Normal file
@ -0,0 +1,7 @@
|
||||
from functools import cached_property
|
||||
|
||||
|
||||
class Foo:
|
||||
@cached_property
|
||||
def prop(self) -> int:
|
||||
return 1
|
@ -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'
|
||||
|
Loading…
Reference in New Issue
Block a user