diff --git a/sphinx_automodapi/autodoc_enhancements.py b/sphinx_automodapi/autodoc_enhancements.py index 8350638..74fb143 100644 --- a/sphinx_automodapi/autodoc_enhancements.py +++ b/sphinx_automodapi/autodoc_enhancements.py @@ -3,7 +3,7 @@ """ import dataclasses -from sphinx.ext.autodoc import AttributeDocumenter +from .utils import SPHINX_LT_8_3 __all__ = [] @@ -80,6 +80,20 @@ def setup(app): if 'app.add_directive' not in app.config.suppress_warnings: app.config.suppress_warnings.append('app.add_directive') try: + if SPHINX_LT_8_3: + from sphinx.ext.autodoc import AttributeDocumenter + + else: + from sphinx.ext.autodoc._directive_options import annotation_option, bool_option + from sphinx.ext.autodoc._documenters import Documenter + + class AttributeDocumenter(Documenter): + """Specialized Documenter subclass for attributes.""" + objtype = 'attribute' + option_spec = dict(Documenter.option_spec) + option_spec['annotation'] = annotation_option + option_spec['no-value'] = bool_option + app.add_autodocumenter(AttributeDocumenter) finally: app.config.suppress_warnings = suppress_warnings_orig