Fixed autodoc directives documenting properties as methods

This commit is contained in:
Ashley Whetter 2020-11-13 21:28:47 -08:00
parent e281137654
commit 06a1969d11
3 changed files with 20 additions and 0 deletions

View File

@ -29,6 +29,7 @@ Bug Fixes
* `#244 <https://github.com/readthedocs/sphinx-autoapi/issues/244>`: * `#244 <https://github.com/readthedocs/sphinx-autoapi/issues/244>`:
Fixed an unnecessary deprecation warning being raised when running Fixed an unnecessary deprecation warning being raised when running
sphinx-build from the same directory as conf.py. sphinx-build from the same directory as conf.py.
* Fixed properties documented by Autodoc directives geting documented as methods.
V1.5.1 (2020-10-01) V1.5.1 (2020-10-01)

View File

@ -212,6 +212,24 @@ class AutoapiMethodDocumenter(
self.add_line(" :{}:".format(property_type), sourcename) self.add_line(" :{}:".format(property_type), sourcename)
class AutoapiPropertyDocumenter(
AutoapiMethodDocumenter, AutoapiDocumenter, autodoc.PropertyDocumenter
):
objtype = "apiproperty"
directivetype = "method"
# Always prefer AutoapiDocumenters
priority = autodoc.MethodDocumenter.priority * 100 + 100 + 1
@classmethod
def can_document_member(cls, member, membername, isattr, parent):
return isinstance(member, PythonMethod) and "property" in member.properties
def add_directive_header(self, sig):
super(AutoapiPropertyDocumenter, self).add_directive_header(sig)
sourcename = self.get_sourcename()
self.add_line(" :property:", sourcename)
class AutoapiDataDocumenter(AutoapiDocumenter, autodoc.DataDocumenter): class AutoapiDataDocumenter(AutoapiDocumenter, autodoc.DataDocumenter):
objtype = "apidata" objtype = "apidata"
directivetype = "data" directivetype = "data"

View File

@ -303,6 +303,7 @@ def setup(app):
app.add_config_value("autoapi_python_class_content", "class", "html") app.add_config_value("autoapi_python_class_content", "class", "html")
app.add_config_value("autoapi_generate_api_docs", True, "html") app.add_config_value("autoapi_generate_api_docs", True, "html")
app.add_autodocumenter(documenters.AutoapiFunctionDocumenter) app.add_autodocumenter(documenters.AutoapiFunctionDocumenter)
app.add_autodocumenter(documenters.AutoapiPropertyDocumenter)
app.add_autodocumenter(documenters.AutoapiDecoratorDocumenter) app.add_autodocumenter(documenters.AutoapiDecoratorDocumenter)
app.add_autodocumenter(documenters.AutoapiClassDocumenter) app.add_autodocumenter(documenters.AutoapiClassDocumenter)
app.add_autodocumenter(documenters.AutoapiMethodDocumenter) app.add_autodocumenter(documenters.AutoapiMethodDocumenter)