diff --git a/CHANGELOG.rst b/CHANGELOG.rst index 275cd8c..61279a1 100644 --- a/CHANGELOG.rst +++ b/CHANGELOG.rst @@ -29,6 +29,7 @@ Bug Fixes * `#244 `: Fixed an unnecessary deprecation warning being raised when running 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) diff --git a/autoapi/documenters.py b/autoapi/documenters.py index 646a581..9082499 100644 --- a/autoapi/documenters.py +++ b/autoapi/documenters.py @@ -212,6 +212,24 @@ class AutoapiMethodDocumenter( 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): objtype = "apidata" directivetype = "data" diff --git a/autoapi/extension.py b/autoapi/extension.py index 60e50cc..3782a4d 100644 --- a/autoapi/extension.py +++ b/autoapi/extension.py @@ -303,6 +303,7 @@ def setup(app): app.add_config_value("autoapi_python_class_content", "class", "html") app.add_config_value("autoapi_generate_api_docs", True, "html") app.add_autodocumenter(documenters.AutoapiFunctionDocumenter) + app.add_autodocumenter(documenters.AutoapiPropertyDocumenter) app.add_autodocumenter(documenters.AutoapiDecoratorDocumenter) app.add_autodocumenter(documenters.AutoapiClassDocumenter) app.add_autodocumenter(documenters.AutoapiMethodDocumenter)