Transport-for-the-North / caf.toolkit

Toolkit of transport planning and appraisal functionalities.
https://caftoolkit.readthedocs.io/en/stable/
Other
0 stars 2 forks source link

Docs: Moved Attribute Docs Out of Docstring #158

Closed MattBuckley-TfN closed 2 weeks ago

MattBuckley-TfN commented 2 weeks ago

Describe Changes

Moved attributes docs to the attribute themselves instead of in the class docstring. Also, removed type annotations from LogHelper docstring as they exist in the signature.

Task Checklist


📚 Documentation preview 📚: https://caftoolkit--158.org.readthedocs.build/en/158/

MattBuckley-TfN commented 2 weeks ago

Noticed an issue with documenting dataclasses (I have confirmed it happens with either pydantic or built-in dataclasses) where the class parameters are automatically added to the docstring.

This causes problems with autosummary because it places the parameters section after the methods and attributes tables but before the attributes docmentation (see image)

image

This can be somewhat "fixed" by documenting the attributes and methods outside the class, although this separates the attributes so they now use their full names and it doesn't look as neat and we can't enable this for dataclasses but use the other method elsewhere.

I don't think the parameters section actually provides any useful information as the parameters are already covered in the Attributes section so I think the preference would be to stick with the current way autosummary displays things and try to remove the additional parameters section that dataclasses seem to add.

I've attached all the different HTML files in this zip archive. ToolDetails docs options.zip

MattBuckley-TfN commented 2 weeks ago

Found a workaround which I think is fairly simple, if we add a parameters section to the class docstring then it places it in the correct location and we can just add links to the attributes which contain more information. Docstring looks like this:

@dataclasses.dataclass
class ToolDetails:
    """Information about the current tool.

    Parameters
    ----------
    name
        See :any:`name`.
    version
        See :any:`version`.
    homepage
        See :any:`homepage`.
    source_url
        See :any:`source_url`.
    """

HTML output looks like:

image

BenTaylor-TfN commented 2 weeks ago

Summarising the discussion from earlier today.

Problems

Solutions

Example

Class ExampleClass:
    """An example class.

    A longer description of this class that can go across
    multiple lines.

    Parameters
    ----------
    param1:
        The first parameter to the constructor.
    """"

    a_class_attribute = 100
    """Class attributes should be documented underneath, like this"""

    def __init__(param1: float):
        self.param1 = param1
        """Attributes can also be documented inside the __init__."""
MattBuckley-TfN commented 2 weeks ago

Are we happy for these changes to be merged as is?