1

I am currently working on a reference documentation that was initially documented manually with .. class:: All classes in the modules where documented this way.

However, it was necessary recently to allow some automation to the documentation, such as show-inheritance of each class, but the problem now is how to combine the current manual documentation with autodoc.

I have tried to just simply replace .. class:: with .. autoclass:: but this resulted in a output where the description and parameters descriptions that were manually typed into the documentation (as against being generated from docstrings) to not be rendered in the output. Can anyone advise on what to do to solve this?

So here is more details:

Take a look at this:

.. autoclass:: wagtail.blocks.CharBlock :show-inheritance: .. class:: CharBlock A single-line text input. The following keyword arguments are accepted in addition to the standard ones: :param required: If true (the default), the field cannot be left blank. :param max_length: The maximum allowed length of the field. :param min_length: The minimum allowed length of the field. :param help_text: Help text to display alongside the field. :param validators: A list of validation functions for the field (see `Django Validators <https://docs.djangoproject.com/en/stable/ref/validators/>`__). :param form_classname: A value to add to the form field's ``class`` attribute when rendered on the page editing form. 

The output: enter image description here

The issue is I have to repeat the class name, which would be rather confusing for the user of the documentation. autoclass would not render the parameters, hence the need for class. I need autoclass to be able to show the inheritance of the class(Bases). So I don't know if there is a directive that can perform the functions of class without me having to mention the class name, or is there any way I can force class not to take in any arguments?

I hope this clearer. Thanks

1
  • You need to be more specific about what the problem is. There is nothing concrete here that we can debug and troubleshoot (see minimal reproducible example). Commented Oct 21, 2022 at 4:14

1 Answer 1

2

It is possible to use autodoc for some things (in this case it's just :show-inheritance:) and "manual" documentation (content that does not come from a docstring) for others, within the same directive.

Remove .. class:: and ensure that all lines after the .. autoclass:: line have the same indentation. I think this should produce the output that you want.

.. autoclass:: wagtail.blocks.CharBlock :show-inheritance: A single-line text input. The following keyword arguments are accepted in addition to the standard ones: :param required: If true (the default), the field cannot be left blank. :param max_length: The maximum allowed length of the field. :param min_length: The minimum allowed length of the field. :param help_text: Help text to display alongside the field. :param validators: A list of validation functions for the field (see `Django Validators <https://docs.djangoproject.com/en/stable/ref/validators/>`__). :param form_classname: A value to add to the form field's ``class`` attribute when rendered on the page editing form. 
Sign up to request clarification or add additional context in comments.

2 Comments

Btw, there is an example of mixing "automatic and non-automatic member documentation" here: sphinx-doc.org/en/master/usage/extensions/….
Yeah, I saw my mistake was indentation

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.